11#include <com/sun/star/lang/XMultiServiceFactory.hpp>
12#include <com/sun/star/drawing/XControlShape.hpp>
13#include <com/sun/star/text/VertOrientation.hpp>
23#include <com/sun/star/text/XTextField.hpp>
26#include <officecfg/Office/Writer.hxx>
27#include <com/sun/star/util/XRefreshable.hpp>
28#include <com/sun/star/text/XTextFieldsSupplier.hpp>
29#include <com/sun/star/document/XOOXMLDocumentPropertiesImporter.hpp>
31#include <com/sun/star/xml/xpath/XPathAPI.hpp>
32#include <com/sun/star/xml/xpath/XPathException.hpp>
33#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
38using namespace ::css::xml::xpath;
43 OUString
const& rDefault, std::vector<OUString>& rItems)
45 OUString aLongest = rDefault;
46 sal_Int32 nHeight = 0;
47 for (
const OUString& rItem : rItems)
48 if (rItem.getLength() > aLongest.getLength())
55 PropertyMapPtr pDefaultCharProps = pStyleSheet->GetDefaultCharProps();
57 std::optional<PropertyMap::Property> aFontName
61 std::optional<PropertyMap::Property> aHeight = pDefaultCharProps->getProperty(
PROP_CHAR_HEIGHT);
64 nHeight = aHeight->second.
get<
double>() * 35;
69 sal_Int32 nWidth =
pOut->GetTextWidth(aLongest);
75 sal_Int32
nBorder = nHeight / 2;
82 css::uno::Reference<css::uno::XComponentContext> xContext)
83 : m_rDM_Impl(rDM_Impl)
86 , m_bHasElements(false)
87 , m_bOutsideAParagraph(false)
88 , m_bPropertiesXMLsLoaded(false)
106 if (!xDomBuilder.is())
114 { OUString(
"{6C3C8BC8-F283-45AE-878A-BAB7291924A1}"),
115 xDomBuilder->parse(xCorePropsStream) });
117 catch (
const uno::Exception&)
120 "SdtHelper::loadPropertiesXMLs: failed loading core properties XML");
129 { OUString(
"{6668398D-A668-4E3E-A5EB-62B293D839F1}"),
130 xDomBuilder->parse(xExtPropsStream) });
132 catch (
const uno::Exception&)
135 "SdtHelper::loadPropertiesXMLs: failed loading extended properties XML");
145 if (aCustomXmls.getLength())
148 xXpathAPI->registerNS(
"ds",
149 "http://schemas.openxmlformats.org/officeDocument/2006/customXml");
155 for (
const auto& xDoc : aCustomXmls)
160 = xXpathAPI->eval(aCustomXmlProps[nItem],
"string(/ds:datastoreItem/@ds:itemID)");
162 if (xResult.is() && xResult->getString().getLength())
164 aStoreId = xResult->getString();
169 "SdtHelper::loadPropertiesXMLs: can't fetch storeid for custom doc!");
184 auto aNamespaces = string::split(sNamespaceString,
' ');
185 for (
const auto& sNamespace : aNamespaces)
188 auto aNamespace = string::split(sNamespace,
'=');
189 if (aNamespace.size() < 2)
192 "SdtHelper::getValueFromDataBinding: invalid namespace: " << sNamespace);
196 auto aNamespaceId = string::split(aNamespace[0],
':');
197 if (aNamespaceId.size() < 2)
200 "SdtHelper::getValueFromDataBinding: invalid namespace: " << aNamespace[0]);
204 OUString sNamespaceURL = aNamespace[1];
205 sNamespaceURL = string::strip(sNamespaceURL,
' ');
206 sNamespaceURL = string::strip(sNamespaceURL,
'\'');
208 xXPathAPI->registerNS(aNamespaceId[1], sNamespaceURL);
235 if (xResult.is() && xResult->getNodeList() && xResult->getNodeList()->getLength()
236 && xResult->getString().getLength())
238 return xResult->getString();
241 catch (
const XPathException& e)
244 SAL_WARN(
"writerfilter",
"SdtHelper::failed running XPath: " << e.Message);
256 if (xResult.is() && xResult->getNodeList() && xResult->getNodeList()->getLength()
257 && xResult->getString().getLength())
259 return xResult->getString();
262 catch (
const XPathException& e)
265 SAL_WARN(
"writerfilter",
"SdtHelper::failed running XPath: " << e.Message);
279 = officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::get();
280 const OUString aDefaultText =
m_aSdtTexts.makeStringAndClear();
289 const auto it = std::find_if(
291 [aDefaultText](
const OUString& item) ->
bool { return !item.compareTo(aDefaultText); });
300 xPropertySet->setPropertyValue(
"SelectedItem",
uno::Any(aDefaultText));
301 xPropertySet->setPropertyValue(
"Items",
318 xPropertySet->setPropertyValue(
"DefaultText",
uno::Any(aDefaultText));
319 xPropertySet->setPropertyValue(
"Dropdown",
uno::Any(
true));
320 xPropertySet->setPropertyValue(
"StringItemList",
337 OUString aDefaultText =
m_aSdtTexts.makeStringAndClear();
348 if (oData.has_value())
349 aDefaultText = *oData;
351 xPropertySet->setPropertyValue(
"Content",
uno::Any(aDefaultText));
373 if (xTextAppend.is())
375 xCrsr = xTextAppend->createTextCursorByRange(xTextAppend);
390 xCrsr->goRight(1,
false);
391 xCrsr->gotoEnd(
true);
393 catch (uno::Exception&)
396 "Cannot get the right text range for date field");
404 if (!(xFormField.is() && xToInsert.is()))
415 sDateFormat = sDateFormat.replaceAll(
"'",
"\"");
420 OUString sFullDate =
m_sDate.makeStringAndClear();
423 if (oData.has_value())
426 if (!sFullDate.isEmpty())
428 sal_Int32 nTimeSep = sFullDate.indexOf(
"T");
430 sFullDate = sFullDate.copy(0, nTimeSep);
438 xRefreshable->refresh();
454 xControlShape->setSize(aSize);
455 xControlShape->setControl(xControlModel);
458 xPropertySet->setPropertyValue(
"VertOrient",
uno::Any(text::VertOrientation::CENTER));
460 if (rGrabBag.hasElements())
488 [&rValueName](
const beans::PropertyValue&
i) { return i.Name == rValueName; });
static OutputDevice * GetDefaultDevice()
void SetFontSize(const Size &)
void SetFamilyName(const OUString &rFamilyName)
bool GetIsDummyParaAddedForTableInSection() const
void appendTextContent(const css::uno::Reference< css::text::XTextContent > &, const css::uno::Sequence< css::beans::PropertyValue > &)
writerfilter::ooxml::OOXMLDocument * getDocumentReference() const
const css::uno::Reference< css::text::XTextDocument > & GetTextDocument() const
const css::uno::Reference< css::lang::XMultiServiceFactory > & GetTextFactory() const
sal_Int32 m_nTableDepth
This contains the raw table depth.
css::uno::Reference< css::embed::XStorage > m_xDocumentStorage
DomainMapperTableManager & getTableManager()
css::uno::Reference< css::text::XTextAppend > const & GetTopTextAppend()
bool hasTableManager() const
StyleSheetTablePtr const & GetStyleSheetTable()
void SetAlias(const OUString &rAlias)
OUStringBuffer m_sDate
Date ISO string contained in the w:date element, used by the date control.
OUString m_sDataBindingPrefixMapping
<w:dataBinding w:prefixMappings="">
const OUString & GetColor() const
void SetCheckedState(const OUString &rCheckedState)
std::optional< OUString > getValueFromDataBinding()
void SetTabIndex(sal_uInt32 nTabIndex)
bool m_bShowingPlcHdr
Current contents are placeholder text.
const OUString & GetCheckedState() const
std::unordered_map< OUString, css::uno::Reference< css::xml::dom::XDocument > > m_xPropertiesXMLs
Storage for all properties documents as xml::dom::XDocument for later querying xpath for data.
sal_uInt32 m_nTabIndex
<w:sdtPr>'s <w:tabIndex w:val="...">.
void SetAppearance(const OUString &rAppearance)
void SetColor(const OUString &rColor)
std::vector< OUString > m_aDropDownDisplayTexts
Display texts of a drop-down control: <w:listItem w:displayText="...">.
const OUString & GetPlaceholderDocPart() const
OUString m_aPlaceholderDocPart
<w:placeholder>'s <w:docPart w:val="...">.
bool containedInInteropGrabBag(const OUString &rValueName)
OUString m_aAlias
<w:sdtPr>'s <w:alias w:val="...">.
std::vector< css::beans::PropertyValue > m_aGrabBag
Grab bag to store unsupported SDTs, aiming to save them back on export.
OUStringBuffer m_sDateFormat
Date format string as it comes from the ooxml document.
std::vector< OUString > m_aDropDownItems
Items of the drop-down control: <w:listItem w:value="...">.
const OUString & GetLock() const
OUString m_aColor
<w:sdtPr>'s <w15:color w:val="...">.
OUStringBuffer m_aSdtTexts
Pieces of the default text – currently used only by the dropdown control.
void appendToInteropGrabBag(const css::beans::PropertyValue &rValue)
const OUString & GetUncheckedState() const
void createDateContentControl()
Create date control from w:sdt's w:date.
bool m_bChecked
If this is a checkbox, is the checkbox checked?
void createControlShape(css::awt::Size aSize, css::uno::Reference< css::awt::XControlModel > const &xControlModel, const css::uno::Sequence< css::beans::PropertyValue > &rGrabBag)
Create and append the drawing::XControlShape, containing the various models.
void createPlainTextControl()
void SetPlaceholderDocPart(const OUString &rPlaceholderDocPart)
bool m_bPropertiesXMLsLoaded
Check if m_xPropertiesXMLs is initialized and loaded (need extra flag to distinguish empty sequence f...
sal_Int32 getInteropGrabBagSize() const
css::uno::Sequence< css::beans::PropertyValue > getInteropGrabBagAndClear()
void SetTag(const OUString &rTag)
OUStringBuffer m_sLocale
Locale string as it comes from the ooxml document.
SdtHelper(DomainMapper_Impl &rDM_Impl, css::uno::Reference< css::uno::XComponentContext > xContext)
void setControlType(SdtControlType aType)
OUString m_sDataBindingStoreItemID
<w:dataBinding w:storeItemID="">
OUString m_aLock
<w:sdtPr>'s <w:lock w:val="...">.
OUString m_sDataBindingXPath
<w:dataBinding w:xpath="">
void loadPropertiesXMLs()
bool GetShowingPlcHdr() const
void clear()
Clear all collected attributes for further reuse.
const OUString & GetAlias() const
void SetId(sal_Int32 nId)
DomainMapper_Impl & m_rDM_Impl
const OUString & GetTag() const
bool isInteropGrabBagEmpty() const
OUString m_aCheckedState
If this is a checkbox, the value of a checked checkbox.
css::uno::Reference< css::text::XTextRange > m_xDateFieldStartRange
Start range of the date field.
SdtControlType getControlType()
void SetUncheckedState(const OUString &rUncheckedState)
sal_Int32 m_nId
<w:sdtPr>'s <w:id w:val="...">.
OUString m_aTag
<w:sdtPr>'s <w:tag w:val="...">.
const OUString & GetAppearance() const
OUString m_aUncheckedState
If this is a checkbox, the value of an unchecked checkbox.
void SetLock(const OUString &rLock)
OUString m_aAppearance
<w:sdtPr>'s <w15:appearance w:val="...">.
sal_uInt32 GetTabIndex() const
void createDropDownControl()
Create drop-down control from w:sdt's w:dropDownList.
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
bool isInTable()
Tells whether a table has been started or not.
virtual css::uno::Sequence< css::uno::Reference< css::xml::dom::XDocument > > getCustomXmlDomList()=0
virtual css::uno::Sequence< css::uno::Reference< css::xml::dom::XDocument > > getCustomXmlDomPropsList()=0
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XComponentContext > const m_xComponentContext
#define SAL_WARN(area, stream)
tools::Long const nBorder
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
static awt::Size lcl_getOptimalWidth(const StyleSheetTablePtr &pStyleSheet, OUString const &rDefault, std::vector< OUString > &rItems)
w:sdt's w:dropDownList doesn't have width, so guess the size based on the longest string.
static void lcl_registerNamespaces(std::u16string_view sNamespaceString, const uno::Reference< XXPathAPI > &xXPathAPI)
HashMap_OWString_Interface aMap
constexpr OUStringLiteral ODF_FORMDATE_CURRENTDATE
constexpr OUStringLiteral ODF_FORMDATE_DATEFORMAT
constexpr OUStringLiteral ODF_FORMDATE
constexpr OUStringLiteral ODF_FORMDATE_DATEFORMAT_LANGUAGE
constexpr OUStringLiteral UNO_NAME_MISC_OBJ_INTEROPGRABBAG