summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper/DomainMapper_Impl.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'writerfilter/source/dmapper/DomainMapper_Impl.cxx')
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 6de9889338b0..854179f51436 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -53,6 +53,8 @@
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <com/sun/star/document/XViewDataSupplier.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
+#include <com/sun/star/awt/XControlModel.hpp>
+#include <com/sun/star/drawing/XControlShape.hpp>
#include <oox/mathml/import.hxx>
#ifdef DEBUG_DOMAINMAPPER
@@ -66,6 +68,8 @@
#include <comphelper/configurationhelper.hxx>
#include <comphelper/stlunosequence.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/outdev.hxx>
using namespace ::com::sun::star;
using namespace ::rtl;
@@ -3933,6 +3937,63 @@ bool DomainMapper_Impl::IsNewDoc()
return m_bIsNewDoc;
}
+/// w:sdt's w:dropDownList doesn't have width, so guess the size based on the longest string.
+awt::Size lcl_getOptimalWidth(StyleSheetTablePtr pStyleSheet, OUString& rDefault, std::vector<OUString>& rItems)
+{
+ OUString aLongest = rDefault;
+ sal_Int32 nHeight = 0;
+ for (size_t i = 0; i < rItems.size(); ++i)
+ if (rItems[i].getLength() > aLongest.getLength())
+ aLongest = rItems[i];
+
+ MapMode aMap(MAP_100TH_MM);
+ OutputDevice* pOut = Application::GetDefaultDevice();
+ pOut->Push(PUSH_FONT | PUSH_MAPMODE);
+
+ PropertyMapPtr pDefaultCharProps = pStyleSheet->GetDefaultCharProps();
+ Font aFont(pOut->GetFont());
+ PropertyMap::iterator aFontName = pDefaultCharProps->find(PropertyDefinition(PROP_CHAR_FONT_NAME, false));
+ if (aFontName != pDefaultCharProps->end())
+ aFont.SetName(aFontName->second.get<OUString>());
+ PropertyMap::iterator aHeight = pDefaultCharProps->find(PropertyDefinition(PROP_CHAR_HEIGHT, false));
+ if (aHeight != pDefaultCharProps->end())
+ {
+ nHeight = aHeight->second.get<double>() * 35; // points -> mm100
+ aFont.SetSize(Size(0, nHeight));
+ }
+ pOut->SetFont(aFont);
+ pOut->SetMapMode(aMap);
+ sal_Int32 nWidth = pOut->GetTextWidth(aLongest);
+
+ pOut->Pop();
+ // Width: space for the text + the square having the dropdown arrow.
+ return awt::Size(nWidth + nHeight, nHeight);
+}
+
+void DomainMapper_Impl::createDropDownControl()
+{
+ OUString aDefaultText = m_aSdtTexts.makeStringAndClear();
+ uno::Reference<awt::XControlModel> xControlModel(m_xTextFactory->createInstance("com.sun.star.form.component.ComboBox"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
+ xPropertySet->setPropertyValue("DefaultText", uno::makeAny(aDefaultText));
+ xPropertySet->setPropertyValue("Dropdown", uno::makeAny(sal_True));
+ uno::Sequence<OUString> aItems(m_aDropDownItems.size());
+ for (size_t i = 0; i < m_aDropDownItems.size(); ++i)
+ aItems[i] = m_aDropDownItems[i];
+ xPropertySet->setPropertyValue("StringItemList", uno::makeAny(aItems));
+
+ uno::Reference<drawing::XControlShape> xControlShape(m_xTextFactory->createInstance("com.sun.star.drawing.ControlShape"), uno::UNO_QUERY);
+ xControlShape->setSize(lcl_getOptimalWidth(GetStyleSheetTable(), aDefaultText, m_aDropDownItems));
+ m_aDropDownItems.clear();
+ xControlShape->setControl(xControlModel);
+
+ xPropertySet.set(xControlShape, uno::UNO_QUERY);
+ xPropertySet->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::CENTER));
+
+ uno::Reference<text::XTextContent> xTextContent(xControlShape, uno::UNO_QUERY);
+ appendTextContent(xTextContent, uno::Sequence< beans::PropertyValue >());
+}
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */