/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** * Content controls are the modern version of FormFields, providing inline functionality similar * to that of ActiveX form controls. Individual content controls may contain contents * such as dates, lists, or paragraphs of formatted text. * * Not all functions are applicable to each type of control, so use getType verification liberally.
*/
SwVbaContentControl::SwVbaContentControl(const uno::Reference<XHelperInterface>& rParent, const uno::Reference<uno::XComponentContext>& rContext, const rtl::Reference<SwXTextDocument>& xTextDocument,
std::shared_ptr<SwContentControl> pContentControl)
: SwVbaContentControl_BASE(rParent, rContext)
, mxTextDocument(xTextDocument)
, m_pCC(std::move(pContentControl))
{
assert(m_pCC && "SwVbaContentControl created without a shared_ptr. Why would you do that?");
}
sal_Int32 SwVbaContentControl::getBuildingBlockType()
{
SAL_INFO("sw.vba", "SwVbaContentControl::getBuildingBlockType stub"); // returns a WdBuildingBlockTypes that represents the type of building block return 0;
}
void SwVbaContentControl::setChecked(sal_Bool bSet)
{ // Word 2010: if locked, then the checked status is changed, but not the underlying text. // Do we really want to do that? That is pretty bizarre behaviour... // For now, just implement what seems to be a more logical response. // TODO: test with modern versions. if (getLockContents()) return;
if (m_pCC->GetCheckbox() && m_pCC->GetChecked() != static_cast<bool>(bSet))
{
m_pCC->SetChecked(bSet);
m_pCC->SetShowingPlaceHolder(false); if (m_pCC->GetTextAttr())
m_pCC->GetTextAttr()->Invalidate();
}
}
sal_Int32 SwVbaContentControl::getColor()
{ //This is just an assumed implementation - I have no testing environment to confirm.
OUString sColor = m_pCC->GetColor(); if (sColor == "wdColorAutomatic") return word::WdColor::wdColorAutomatic; if (sColor == "wdColorBlack") return word::WdColor::wdColorBlack; if (sColor == "wdColorBlue") return word::WdColor::wdColorBlue; if (sColor == "wdColorBlueGray") return word::WdColor::wdColorBlueGray; if (sColor == "wdColorBrightGreen") return word::WdColor::wdColorBrightGreen; if (sColor == "wdColorBrown") return word::WdColor::wdColorBrown; if (sColor == "wdColorDarkBlue") return word::WdColor::wdColorDarkBlue; if (sColor == "wdColorDarkGreen") return word::WdColor::wdColorDarkGreen; if (sColor == "wdColorDarkRed") return word::WdColor::wdColorDarkRed; if (sColor == "wdColorDarkTeal") return word::WdColor::wdColorDarkTeal; if (sColor == "wdColorDarkYellow") return word::WdColor::wdColorDarkYellow; if (sColor == "wdColorGold") return word::WdColor::wdColorGold; if (sColor == "wdColorGray05") return word::WdColor::wdColorGray05; if (sColor == "wdColorGray10") return word::WdColor::wdColorGray10; if (sColor == "wdColorGray125") return word::WdColor::wdColorGray125; if (sColor == "wdColorGray15") return word::WdColor::wdColorGray15; if (sColor == "wdColorGray20") return word::WdColor::wdColorGray20; if (sColor == "wdColorGray25") return word::WdColor::wdColorGray25; if (sColor == "wdColorGray30") return word::WdColor::wdColorGray30; if (sColor == "wdColorGray35") return word::WdColor::wdColorGray35; if (sColor == "wdColorGray375") return word::WdColor::wdColorGray375; if (sColor == "wdColorGray40") return word::WdColor::wdColorGray40; if (sColor == "wdColorGray45") return word::WdColor::wdColorGray45; if (sColor == "wdColorGray50") return word::WdColor::wdColorGray50; if (sColor == "wdColorGray55") return word::WdColor::wdColorGray55; if (sColor == "wdColorGray60") return word::WdColor::wdColorGray60; if (sColor == "wdColorGray625") return word::WdColor::wdColorGray625; if (sColor == "wdColorGray65") return word::WdColor::wdColorGray65; if (sColor == "wdColorGray70") return word::WdColor::wdColorGray70; if (sColor == "wdColorGray75") return word::WdColor::wdColorGray75; if (sColor == "wdColorGray80") return word::WdColor::wdColorGray80; if (sColor == "wdColorGray85") return word::WdColor::wdColorGray85; if (sColor == "wdColorGray875") return word::WdColor::wdColorGray875; if (sColor == "wdColorGray90") return word::WdColor::wdColorGray90; if (sColor == "wdColorGray95") return word::WdColor::wdColorGray95; if (sColor == "wdColorGreen") return word::WdColor::wdColorGreen; if (sColor == "wdColorIndigo") return word::WdColor::wdColorIndigo; if (sColor == "wdColorLavender") return word::WdColor::wdColorLavender; if (sColor == "wdColorLightBlue") return word::WdColor::wdColorLightBlue; if (sColor == "wdColorLightGreen") return word::WdColor::wdColorLightGreen; if (sColor == "wdColorLightOrange") return word::WdColor::wdColorLightOrange; if (sColor == "wdColorLightTurquoise") return word::WdColor::wdColorLightTurquoise; if (sColor == "wdColorLightYellow") return word::WdColor::wdColorLightYellow; if (sColor == "wdColorLime") return word::WdColor::wdColorLime; if (sColor == "wdColorOliveGreen") return word::WdColor::wdColorOliveGreen; if (sColor == "wdColorOrange") return word::WdColor::wdColorOrange; if (sColor == "wdColorPaleBlue") return word::WdColor::wdColorPaleBlue; if (sColor == "wdColorPink") return word::WdColor::wdColorPink; if (sColor == "wdColorPlum") return word::WdColor::wdColorPlum; if (sColor == "wdColorRed") return word::WdColor::wdColorRed; if (sColor == "wdColorRose") return word::WdColor::wdColorRose; if (sColor == "wdColorSeaGreen") return word::WdColor::wdColorSeaGreen; if (sColor == "wdColorSkyBlue") return word::WdColor::wdColorSkyBlue; if (sColor == "wdColorTan") return word::WdColor::wdColorTan; if (sColor == "wdColorTeal") return word::WdColor::wdColorTeal; if (sColor == "wdColorTurquoise") return word::WdColor::wdColorTurquoise; if (sColor == "wdColorViolet") return word::WdColor::wdColorViolet; if (sColor == "wdColorWhite") return word::WdColor::wdColorWhite; if (sColor == "wdColorYellow") return word::WdColor::wdColorYellow;
return word::WdColor::wdColorBlack;
}
void SwVbaContentControl::setColor(sal_Int32 nWdColor)
{ switch (nWdColor)
{ case word::WdColor::wdColorAqua:
m_pCC->SetColor(u"wdColorAqua"_ustr); break; case word::WdColor::wdColorAutomatic:
m_pCC->SetColor(u"wdColorAutomatic"_ustr); break; case word::WdColor::wdColorBlack:
m_pCC->SetColor(u"wdColorBlack"_ustr); break; case word::WdColor::wdColorBlue:
m_pCC->SetColor(u"wdColorBlue"_ustr); break; case word::WdColor::wdColorBlueGray:
m_pCC->SetColor(u"wdColorBlueGray"_ustr); break; case word::WdColor::wdColorBrightGreen:
m_pCC->SetColor(u"wdColorBrightGreen"_ustr); break; case word::WdColor::wdColorBrown:
m_pCC->SetColor(u"wdColorBrown"_ustr); break; case word::WdColor::wdColorDarkBlue:
m_pCC->SetColor(u"wdColorDarkBlue"_ustr); break; case word::WdColor::wdColorDarkGreen:
m_pCC->SetColor(u"wdColorDarkGreen"_ustr); break; case word::WdColor::wdColorDarkRed:
m_pCC->SetColor(u"wdColorDarkRed"_ustr); break; case word::WdColor::wdColorDarkTeal:
m_pCC->SetColor(u"wdColorDarkTeal"_ustr); break; case word::WdColor::wdColorDarkYellow:
m_pCC->SetColor(u"wdColorDarkYellow"_ustr); break; case word::WdColor::wdColorGold:
m_pCC->SetColor(u"wdColorGold"_ustr); break; case word::WdColor::wdColorGray05:
m_pCC->SetColor(u"wdColorGray05"_ustr); break; case word::WdColor::wdColorGray10:
m_pCC->SetColor(u"wdColorGray10"_ustr); break; case word::WdColor::wdColorGray125:
m_pCC->SetColor(u"wdColorGray125"_ustr); break; case word::WdColor::wdColorGray15:
m_pCC->SetColor(u"wdColorGray15"_ustr); break; case word::WdColor::wdColorGray20:
m_pCC->SetColor(u"wdColorGray20"_ustr); break; case word::WdColor::wdColorGray25:
m_pCC->SetColor(u"wdColorGray25"_ustr); break; case word::WdColor::wdColorGray30:
m_pCC->SetColor(u"wdColorGray30"_ustr); break; case word::WdColor::wdColorGray35:
m_pCC->SetColor(u"wdColorGray35"_ustr); break; case word::WdColor::wdColorGray375:
m_pCC->SetColor(u"wdColorGray375"_ustr); break; case word::WdColor::wdColorGray40:
m_pCC->SetColor(u"wdColorGray40"_ustr); break; case word::WdColor::wdColorGray45:
m_pCC->SetColor(u"wdColorGray45"_ustr); break; case word::WdColor::wdColorGray50:
m_pCC->SetColor(u"wdColorGray50"_ustr); break; case word::WdColor::wdColorGray55:
m_pCC->SetColor(u"wdColorGray55"_ustr); break; case word::WdColor::wdColorGray60:
m_pCC->SetColor(u"wdColorGray60"_ustr); break; case word::WdColor::wdColorGray625:
m_pCC->SetColor(u"wdColorGray625"_ustr); break; case word::WdColor::wdColorGray65:
m_pCC->SetColor(u"wdColorGray65"_ustr); break; case word::WdColor::wdColorGray70:
m_pCC->SetColor(u"wdColorGray70"_ustr); break; case word::WdColor::wdColorGray75:
m_pCC->SetColor(u"wdColorGray75"_ustr); break; case word::WdColor::wdColorGray80:
m_pCC->SetColor(u"wdColorGray80"_ustr); break; case word::WdColor::wdColorGray85:
m_pCC->SetColor(u"wdColorGray85"_ustr); break; case word::WdColor::wdColorGray875:
m_pCC->SetColor(u"wdColorGray875"_ustr); break; case word::WdColor::wdColorGray90:
m_pCC->SetColor(u"wdColorGray90"_ustr); break; case word::WdColor::wdColorGray95:
m_pCC->SetColor(u"wdColorGray95"_ustr); break; case word::WdColor::wdColorGreen:
m_pCC->SetColor(u"wdColorGreen"_ustr); break; case word::WdColor::wdColorIndigo:
m_pCC->SetColor(u"wdColorIndigo"_ustr); break; case word::WdColor::wdColorLavender:
m_pCC->SetColor(u"wdColorLavender"_ustr); break; case word::WdColor::wdColorLightBlue:
m_pCC->SetColor(u"wdColorLightBlue"_ustr); break; case word::WdColor::wdColorLightGreen:
m_pCC->SetColor(u"wdColorLightGreen"_ustr); break; case word::WdColor::wdColorLightOrange:
m_pCC->SetColor(u"wdColorLightOrange"_ustr); break; case word::WdColor::wdColorLightTurquoise:
m_pCC->SetColor(u"wdColorLightTurquoise"_ustr); break; case word::WdColor::wdColorLightYellow:
m_pCC->SetColor(u"wdColorLightYellow"_ustr); break; case word::WdColor::wdColorLime:
m_pCC->SetColor(u"wdColorLime"_ustr); break; case word::WdColor::wdColorOliveGreen:
m_pCC->SetColor(u"wdColorOliveGreen"_ustr); break; case word::WdColor::wdColorOrange:
m_pCC->SetColor(u"wdColorOrange"_ustr); break; case word::WdColor::wdColorPaleBlue:
m_pCC->SetColor(u"wdColorPaleBlue"_ustr); break; case word::WdColor::wdColorPink:
m_pCC->SetColor(u"wdColorPink"_ustr); break; case word::WdColor::wdColorPlum:
m_pCC->SetColor(u"wdColorPlum"_ustr); break; case word::WdColor::wdColorRed:
m_pCC->SetColor(u"wdColorRed"_ustr); break; case word::WdColor::wdColorRose:
m_pCC->SetColor(u"wdColorRose"_ustr); break; case word::WdColor::wdColorSeaGreen:
m_pCC->SetColor(u"wdColorSeaGreen"_ustr); break; case word::WdColor::wdColorSkyBlue:
m_pCC->SetColor(u"wdColorSkyBlue"_ustr); break; case word::WdColor::wdColorTan:
m_pCC->SetColor(u"wdColorTan"_ustr); break; case word::WdColor::wdColorTeal:
m_pCC->SetColor(u"wdColorTeal"_ustr); break; case word::WdColor::wdColorTurquoise:
m_pCC->SetColor(u"wdColorTurquoise"_ustr); break; case word::WdColor::wdColorViolet:
m_pCC->SetColor(u"wdColorViolet"_ustr); break; case word::WdColor::wdColorWhite:
m_pCC->SetColor(u"wdColorWhite"_ustr); break; default:;
}
}
sal_Int32 SwVbaContentControl::getDateCalendarType()
{
SAL_INFO("sw.vba", "SwVbaContentControl::getDateCalendarType stub"); // returns a WdCalendarTypes that represents the type of building block return word::WdCalendarType::wdCalendarWestern;
}
sal_Int32 SwVbaContentControl::getDateStorageFormat()
{
SAL_INFO("sw.vba", "SwVbaContentControl::getDateStorageFormat stub"); // returns a WdContentControlDateStorageFormat when bound to the XML data store. return 0;
}
sal_Int32 SwVbaContentControl::getDateDisplayLocale()
{
SAL_INFO("sw.vba", "SwVbaContentControl::getDateDisplayLocale stub"); // returns a WdLanguageID that represents the language format for a date content control. return word::WdLanguageID::wdEnglishUS;
}
uno::Any SwVbaContentControl::getDropdownListEntries()
{ if (!m_pCC->GetDropDown() && !m_pCC->GetComboBox()) return uno::Any();
OUString SwVbaContentControl::getID()
{ // This signed integer is treated in VBA as if it was an unsigned int. return OUString::number(static_cast<sal_uInt32>(m_pCC->GetId()));
}
sal_Bool SwVbaContentControl::getLockContents()
{ // If the theoretical design model says it is locked, then report as locked.
std::optional<bool> oLock = m_pCC->GetLock(/*bControl=*/false); if (oLock.has_value() && *oLock) returntrue;
// Now check the real implementation. // Checkbox/DropDown/Picture are normally locked - but not in this sense. Report as unlocked. if (m_pCC->GetType() == SwContentControlType::CHECKBOX
|| m_pCC->GetType() == SwContentControlType::DROP_DOWN_LIST
|| m_pCC->GetType() == SwContentControlType::PICTURE)
{ returnfalse;
}
return m_pCC->GetReadWrite();
}
void SwVbaContentControl::setLockContents(sal_Bool bSet)
{ // Set the lock both theoretically and actually.
std::optional<bool> oLock = m_pCC->GetLock(/*bControl=*/true);
m_pCC->SetLock(/*bContents=*/bSet, /*bControl=*/oLock.has_value() && *oLock);
// Checkbox/DropDown/Picture are normally locked in LO implementation - don't unlock them. if (m_pCC->GetType() == SwContentControlType::CHECKBOX
|| m_pCC->GetType() == SwContentControlType::DROP_DOWN_LIST
|| m_pCC->GetType() == SwContentControlType::PICTURE)
{ return;
}
m_pCC->SetReadWrite(bSet);
}
OUString SwVbaContentControl::getPlaceholderText()
{ // return m_pCC->GetPlaceholderDocPart(); // This is not correct. Much more complex than this...
SAL_INFO("sw.vba", "SwVbaContentControl::getPlaceholderText stub"); return OUString();
}
sal_Bool SwVbaContentControl::getTemporary()
{
SAL_INFO("sw.vba", "SwVbaContentControl::getTemporary stub"); // Is content control removed when user edits (one time use)? Not implemented in LO. returnfalse;
}
void SwVbaContentControl::SetCheckedSymbol(sal_Int32 Character, const uno::Any& Font)
{ if (!m_pCC->GetTextAttr()) return;
SAL_INFO_IF(Font.hasValue(), "sw.vba", "SetCheckedSymbol Font[" << Font << "] stub"); if (Character < 31 || Character > SAL_MAX_UINT16) return; // unsupported character. Would such a thing exist in VBA?
if (m_pCC->GetCheckbox() && m_pCC->GetChecked() && !m_pCC->GetShowingPlaceHolder())
m_pCC->GetTextAttr()->Invalidate();
}
void SwVbaContentControl::SetUnCheckedSymbol(sal_Int32 Character, const uno::Any& Font)
{ if (!m_pCC->GetTextAttr()) return;
SAL_INFO_IF(Font.hasValue(), "sw.vba", "SetUnCheckedSymbol Font[" << Font << "] stub"); if (Character < 31 || Character > SAL_MAX_UINT16) return; // unsupported character. Would such a thing exist in VBA?
if (m_pCC->GetCheckbox() && !m_pCC->GetChecked() && !m_pCC->GetShowingPlaceHolder())
m_pCC->GetTextAttr()->Invalidate();
}
void SwVbaContentControl::SetPlaceholderText(const uno::Any& BuildingBlock, const uno::Any& Range, const uno::Any& Text)
{
SAL_INFO("sw.vba", "SwVbaContentControl::SetPlaceholderText stub"); if (BuildingBlock.hasValue())
{ // Set placeholder text to the building block - whatever that is.
} elseif (Range.hasValue())
{ // Set placeholder text to the contents of the Range, however you do that.
} elseif (Text.hasValue())
{ // Set placeholder text to the provided string
} else
{ // Remove placeholder text.
m_pCC->SetPlaceholderDocPart(u""_ustr);
} if (m_pCC->GetShowingPlaceHolder() && !getLockContents() && m_pCC->GetTextAttr())
{ //replace the text and ensure showing placeholder is still set
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.