21#include <com/sun/star/awt/Size.hpp>
22#include <com/sun/star/awt/Point.hpp>
23#include <com/sun/star/container/XNameAccess.hpp>
24#include <com/sun/star/drawing/ShapeCollection.hpp>
25#include <com/sun/star/drawing/XShapes.hpp>
26#include <com/sun/star/drawing/XShapeGrouper.hpp>
27#include <com/sun/star/text/TextContentAnchorType.hpp>
28#include <com/sun/star/view/XSelectionSupplier.hpp>
38#define BUTTON_HEIGHT 300
60 Reference< XShapes > xPageShapes = _rContext.
xDrawPage;
61 if (!xPageShapes.is())
63 OSL_FAIL(
"OOptionGroupLayouter::OOptionGroupLayouter: missing the XShapes interface for the page!");
68 if (!xDocFactory.is())
70 OSL_FAIL(
"OOptionGroupLayouter::OOptionGroupLayouter: no document service factory!");
75 sal_Int32 nRadioButtons = _rSettings.
aLabels.size();
78 css::awt::Size aControlShapeSize = _rContext.
xObjectShape->getSize();
81 if (aControlShapeSize.Height < nMinShapeHeight)
82 aControlShapeSize.Height = nMinShapeHeight;
91 Reference< XShapes > xButtonCollection( ShapeCollection::create(
mxContext) );
95 sal_Int32 nTempHeight = (aControlShapeSize.Height -
BUTTON_HEIGHT/4) / (nRadioButtons + 1);
97 css::awt::Point aShapePosition = _rContext.
xObjectShape->getPosition();
99 css::awt::Size aButtonSize(aControlShapeSize);
100 aButtonSize.Width = aControlShapeSize.Width -
OFFSET;
101 aButtonSize.Height =
HEIGHT;
102 css::awt::Point aButtonPosition;
103 aButtonPosition.X = aShapePosition.X +
OFFSET;
105 OUString sElementsName(
"RadioGroup");
108 auto aLabelIter = _rSettings.
aLabels.cbegin();
109 auto aValueIter = _rSettings.
aValues.cbegin();
110 for (sal_Int32
i=0;
i<nRadioButtons; ++
i, ++aLabelIter, ++aValueIter)
112 aButtonPosition.Y = aShapePosition.Y + (
i+1) * nTempHeight;
114 Reference< XPropertySet > xRadioModel(
115 xDocFactory->createInstance(
"com.sun.star.form.component.RadioButton"),
119 xRadioModel->setPropertyValue(
"Label",
Any(*aLabelIter));
121 xRadioModel->setPropertyValue(
"RefValue",
Any(*aValueIter));
125 xRadioModel->setPropertyValue(
"DefaultState",
Any(sal_Int16(1)));
129 xRadioModel->setPropertyValue(
"DataField",
Any(_rSettings.
sDBField));
132 xRadioModel->setPropertyValue(
"Name",
Any(sElementsName));
135 Reference< XControlShape > xRadioShape(
136 xDocFactory->createInstance(
"com.sun.star.drawing.ControlShape"),
138 Reference< XPropertySet > xShapeProperties(xRadioShape, UNO_QUERY);
144 xRadioShape->setSize(aButtonSize);
145 xRadioShape->setPosition(aButtonPosition);
147 xRadioShape->setControl(Reference< XControlModel >(xRadioModel, UNO_QUERY));
161 xPageShapes->add(xRadioShape);
163 xButtonCollection->add(xRadioShape);
167 xRadioModel->setPropertyValue(
"LabelControl",
Any(_rContext.
xObjectModel));
173 Reference< XShapeGrouper > xGrouper(_rContext.
xDrawPage, UNO_QUERY);
176 Reference< XShapeGroup > xGroupedOptions = xGrouper->group(xButtonCollection);
177 Reference< XSelectionSupplier > xSelector(_rContext.
xDocumentModel->getCurrentController(), UNO_QUERY);
179 xSelector->select(
Any(xGroupedOptions));
185 "caught an exception while grouping the shapes!");
192 static constexpr OUStringLiteral s_sAnchorPropertyName =
u"AnchorType";
193 Reference< XPropertySetInfo > xPropertyInfo;
194 if (_rxShapeProps.is())
195 xPropertyInfo = _rxShapeProps->getPropertySetInfo();
196 if (xPropertyInfo.is() && xPropertyInfo->hasPropertyByName(s_sAnchorPropertyName))
197 _rxShapeProps->setPropertyValue(s_sAnchorPropertyName,
Any(TextContentAnchorType_AT_PAGE));
OOptionGroupLayouter(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
void doLayout(const OControlWizardContext &_rContext, const OOptionGroupSettings &_rSettings)
static void implAnchorShape(const css::uno::Reference< css::beans::XPropertySet > &_rxShapeProps)
css::uno::Reference< css::uno::XComponentContext > mxContext
#define TOOLS_WARN_EXCEPTION(area, stream)
void disambiguateName(const Reference< XNameAccess > &_rxContainer, OUString &_rElementsName)
css::uno::Reference< css::beans::XPropertySet > xObjectModel
css::uno::Reference< css::drawing::XControlShape > xObjectShape
css::uno::Reference< css::frame::XModel > xDocumentModel
css::uno::Reference< css::drawing::XDrawPage > xDrawPage
css::uno::Reference< css::beans::XPropertySet > xForm
std::vector< OUString > aLabels
std::vector< OUString > aValues