35 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
36 #include <com/sun/star/view/DocumentZoomType.hpp>
49 #include <osl/file.hxx>
51 #include <unoprnms.hxx>
64 #define DEFAULT_LEFT_DISTANCE (MM50*5) // 2,5 cm
65 #define DEFAULT_TOP_DISTANCE (MM50*11) // 5,5 cm
66 #define GREETING_TOP_DISTANCE (MM50*25) //12,5 cm
67 #define DEFAULT_ADDRESS_WIDTH (MM50*15)// 7,5 cm
68 #define DEFAULT_ADDRESS_HEIGHT (MM50*7) // 3,5cm
71 :
vcl::OWizardPage(pPage, pWizard,
"modules/swriter/ui/mmlayoutpage.ui",
"MMLayoutPage")
72 , m_pExampleWrtShell(nullptr)
73 , m_pAddressBlockFormat(nullptr)
74 , m_bIsGreetingInserted(false)
76 , m_xPosition(m_xBuilder->weld_container(
"addresspos"))
77 , m_xAlignToBodyCB(m_xBuilder->weld_check_button(
"align"))
78 , m_xLeftFT(m_xBuilder->weld_label(
"leftft"))
79 , m_xLeftMF(m_xBuilder->weld_metric_spin_button(
"left",
FieldUnit::
CM))
80 , m_xTopMF(m_xBuilder->weld_metric_spin_button(
"top",
FieldUnit::
CM))
81 , m_xGreetingLine(m_xBuilder->weld_container(
"greetingspos"))
82 , m_xUpPB(m_xBuilder->weld_button(
"up"))
83 , m_xDownPB(m_xBuilder->weld_button(
"down"))
84 , m_xZoomLB(m_xBuilder->weld_combo_box(
"zoom"))
86 std::shared_ptr<const SfxFilter> pSfxFlt =
87 SwDocShell::Factory().GetFilterContainer()->
88 GetFilter4FilterName(
"writer8", SfxFilterFlags::EXPORT);
101 uno::Sequence< beans::PropertyValue > aValues(2);
102 beans::PropertyValue*
pValues = aValues.getArray();
103 pValues[0].Name =
"FilterName";
104 pValues[0].Value <<= pSfxFlt->GetFilterName();
106 pValues[1].Name =
"NoEmbDataSet";
107 pValues[1].Value <<=
true;
109 uno::Reference< frame::XStorable > xStore( pView->
GetDocShell()->
GetModel(), uno::UNO_QUERY);
133 m_xLeftMF->connect_value_changed(aFrameHdl);
134 m_xTopMF->connect_value_changed(aFrameHdl);
137 ::SetFieldUnit( *
m_xLeftMF, eFieldUnit );
138 ::SetFieldUnit( *
m_xTopMF, eFieldUnit );
141 m_xUpPB->connect_clicked(aUpDownHdl);
224 const Point& rAddressPosition,
233 if(rAddressPosition.X() > 0 && rAddressPosition.Y() > 0)
234 aAddressPosition = rAddressPosition;
237 aAddressPosition, bAlignToBody,
false);
247 return pAddressBlockFormat;
253 const Point& rDestination,
278 OSL_ENSURE( pRet,
"Fly not inserted" );
284 rShell.
Insert(aBlocks[0]);
294 const OUString sDatabaseConditionPrefix(sDBName.replace(
DB_DELIM,
'.'));
304 bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
309 const OUString* pAssignment = aAssignment.getConstArray();
310 const OUString sCountryColumn(
311 (aAssignment.getLength() > MM_PART_COUNTRY && !aAssignment[MM_PART_COUNTRY].isEmpty())
312 ? aAssignment[MM_PART_COUNTRY]
313 : rHeaders[MM_PART_COUNTRY].
first);
315 OUString sHideParagraphsExpression;
322 OUString sConvertedColumn = aItem.
sText;
323 auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
324 static_cast<sal_uInt32>(aAssignment.getLength()));
325 for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
327 if (rHeaders[nColumn].first == aItem.
sText &&
328 !pAssignment[nColumn].isEmpty())
330 sConvertedColumn = pAssignment[nColumn];
334 const OUString sDB(sDBName + sConvertedColumn);
336 if(!sHideParagraphsExpression.isEmpty())
337 sHideParagraphsExpression +=
" AND ";
338 sHideParagraphsExpression +=
"![" + sDatabaseConditionPrefix + sConvertedColumn +
"]";
340 if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
343 if( !rExcludeCountry.isEmpty() )
345 const OUString sExpression(
"[" + sDatabaseConditionPrefix + sCountryColumn +
"]");
347 sExpression +
" != \"" + rExcludeCountry +
"\"",
370 if(bHideEmptyParagraphs)
375 sHideParagraphsExpression.clear();
380 if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
426 if( !bExample && 0 != nMoves )
456 rConfigItem.
GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
457 sal_Int32 nCurrent = rConfigItem.
GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
458 if( nCurrent >= 0 && nCurrent < aEntries.getLength())
461 rShell.
Insert(aEntries[nCurrent]);
480 const OUString sConditionBase(
"[" + sCommonBase + sGenderColumn +
"]");
481 const OUString sNameColumnBase(
"[" + sCommonBase + sNameColumn +
"]");
490 OSL_ENSURE(!sGenderColumn.isEmpty() && !rFemaleGenderValue.isEmpty(),
491 "gender settings not available - how to form the condition?");
497 sal_Int32 nCurrent = rConfigItem.
GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
498 if( nCurrent >= 0 && nCurrent < aEntries.getLength())
500 const OUString sGreeting = aEntries[nCurrent];
502 OUString sHideParagraphsExpression;
506 sCondition = sConditionBase +
" != \"" + rFemaleGenderValue
507 +
"\" OR NOT " + sNameColumnBase;
508 sHideParagraphsExpression =
"!" + sNameColumnBase;
511 sCondition = sConditionBase +
" == \"" + rFemaleGenderValue
512 +
"\" OR NOT " + sNameColumnBase;
515 sCondition = sNameColumnBase;
519 if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
521 OUString sComplete =
"(" + sCondition +
") OR (" + sHideParagraphsExpression +
")";
534 const OUString* pAssignment = aAssignment.getConstArray();
541 OUString sConvertedColumn = aItem.
sText;
542 auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
543 static_cast<sal_uInt32>(aAssignment.getLength()));
544 for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
547 !pAssignment[nColumn].isEmpty())
549 sConvertedColumn = pAssignment[nColumn];
554 sDBName + sConvertedColumn,
555 OUString(), 0, &rShell);
576 rShell.
Insert(( nCurrent >= 0 && nCurrent < aEntries.getLength() )
577 ? aEntries[nCurrent] : OUString());
589 OSL_ENSURE(
nullptr == rShell.
GetTableFormat(),
"What to do with a table here?");
594 m_xExampleContainerWIN->show();
596 Reference< XModel > &
xModel = m_xExampleFrame->GetModel();
598 Reference< XViewSettingsSupplier > xSettings(xModel->getCurrentController(), UNO_QUERY);
599 m_xViewProperties = xSettings->getViewSettings();
600 auto pXDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(xModel);
603 OSL_ENSURE(m_pExampleWrtShell,
"No SwWrtShell found!");
604 if(!m_pExampleWrtShell)
610 m_pAddressBlockFormat = InsertAddressFrame(
611 *m_pExampleWrtShell, rConfigItem,
613 m_xAlignToBodyCB->get_active(),
true);
617 InsertGreeting(*m_pExampleWrtShell, rConfigItem,
true);
618 m_bIsGreetingInserted =
true;
621 ZoomHdl_Impl(*m_xZoomLB);
624 m_pExampleWrtShell->GetCurPageDesc()).GetMaster().GetFrameSize();
631 if (!m_pExampleWrtShell)
634 sal_Int16
eType = DocumentZoomType::BY_VALUE;
636 switch (rBox.get_active())
638 case 0 : eType = DocumentZoomType::ENTIRE_PAGE;
break;
639 case 1 : nZoom = 50;
break;
640 case 2 : nZoom = 75;
break;
641 case 3 : nZoom = 100;
break;
649 m_xExampleFrame->Invalidate();
654 if(!(m_pExampleWrtShell && m_pAddressBlockFormat))
657 tools::Long nLeft =
static_cast< tools::Long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
658 tools::Long nTop =
static_cast< tools::Long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
661 m_pExampleWrtShell->GetAttrPool(),
663 if (m_xAlignToBodyCB->get_active())
668 m_pExampleWrtShell->GetDoc()->SetFlyFrameAttr( *m_pAddressBlockFormat, aSet );
669 m_xExampleFrame->Invalidate();
674 bool bDown = &rButton == m_xDownPB.get();
675 bool bMoved = m_pExampleWrtShell->MoveParagraph( bDown ? 1 : -1 );
677 m_pWizard->GetConfigItem().MoveGreeting(bDown ? 1 : -1 );
681 m_pExampleWrtShell->SplitNode();
683 m_xExampleFrame->Invalidate();
688 bool bCheck = rBox.get_active() && rBox.get_sensitive();
689 m_xLeftFT->set_sensitive(!bCheck);
690 m_xLeftMF->set_sensitive(!bCheck);
691 ChangeAddressHdl_Impl( *m_xLeftMF );
#define LINK(Instance, Class, Member)
std::unique_ptr< weld::Button > m_xUpPB
SwMergeAddressItem Next()
bool IsHideEmptyParagraphs() const
tools::Long GetWidth() const
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
bool SttPara(bool bSelect=false)
void SplitNode(bool bAutoFormat=false)
bool IsAddressInserted() const
#define DEFAULT_LEFT_DISTANCE
bool DelFullPara()
Remove a complete paragraph.
#define UNO_NAME_ZOOM_VALUE
SwMailMergeConfigItem & GetConfigItem()
#define DEFAULT_ADDRESS_WIDTH
bool SttEndDoc(bool bStt)
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
const LanguageTag & GetUILanguageTag() const
void Left(const tools::Long nLeft)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
const SwRect & GetAnyCurRect(CurRectType eType, const Point *pPt=nullptr, const css::uno::Reference< css::embed::XEmbeddedObject > &=css::uno::Reference< css::embed::XEmbeddedObject >()) const
#define UNO_NAME_ZOOM_TYPE
OUString & GetExcludeCountry() const
static const AllSettings & GetSettings()
std::unique_ptr< SwOneExampleFrame > m_xExampleFrame
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
SwMoveFnCollection const & fnParaStart
const ContentProperties & rData
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
#define DEFAULT_ADDRESS_HEIGHT
const SwDBData & GetCurrentDBData() const
sal_Int32 GetGreetingMoves() const
std::unique_ptr< weld::Builder > m_xBuilder
css::uno::Reference< css::frame::XModel > GetModel() const
std::unique_ptr< weld::MetricSpinButton > m_xLeftMF
Of course Writer needs its own rectangles.
bool InsertField(const SwInsertField_Data &rData)
Value in Var-direction gives minimum (can be exceeded but not be less).
std::unique_ptr< weld::ComboBox > m_xZoomLB
SwWrtShell & GetWrtShell() const
Used by the UI to modify the document model.
bool GotoFly(const OUString &rName, FlyCntType eType=FLYCNTTYPE_ALL, bool bSelFrame=true)
#define GREETING_TOP_DISTANCE
static SwFrameFormat * InsertAddressFrame(SwWrtShell &rShell, SwMailMergeConfigItem const &rConfigItem, const Point &rDestination, bool bAlignToBody, bool bExample)
css::uno::Sequence< OUString > GetAddressBlocks() const
static SwFrameFormat * InsertAddressAndGreeting(SwView const *pView, SwMailMergeConfigItem &rConfigItem, const Point &rAddressPos, bool bAlignToBody)
#define DEFAULT_TOP_DISTANCE
SwMailMergeLayoutPage(weld::Container *pPage, SwMailMergeWizard *pWizard)
static void InsertGreeting(SwWrtShell &rShell, SwMailMergeConfigItem const &rConfigItem, bool bExample)
css::uno::Sequence< OUString > GetGreetings(Gender eType) const
void Insert(SwField const &, SwPaM *pAnnotationRange=nullptr)
void SetGreetingInserted()
bool MoveParagraph(tools::Long nOffset=1)
std::unique_ptr< weld::CustomWeld > m_xExampleContainerWIN
constexpr OUStringLiteral aData
bool MovePara(SwWhichPara, SwMoveFnCollection const &)
bool IsGreetingInserted() const
const SfxItemPool & GetAttrPool() const
IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, weld::ComboBox &, rBox, void)
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
bool SetShadowCursorPos(const Point &rPt, SwFillMode eFillMode)
OUString const & GetURL() const
std::unique_ptr< weld::Button > m_xDownPB
void Push()
store a copy of the current cursor on the cursor stack
std::unique_ptr< weld::Container > m_xPosition
virtual ~SwMailMergeLayoutPage() override
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
tools::Long Width() const
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
tools::Long GetHeight() const
std::unique_ptr< weld::CheckButton > m_xAlignToBodyCB
SwDocShell * GetDocShell()
SwFrameFormat * GetTableFormat()
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
void SetAddressInserted()
sal_Int32 GetCurrentGreeting(Gender eType) const
std::unique_ptr< weld::MetricSpinButton > m_xTopMF
const PropertyValue * pValues
bool IsIndividualGreeting(bool bInEMail) const
SwMailMergeWizard * m_pWizard
const SwFrameFormat * NewFlyFrame(const SfxItemSet &rSet, bool bAnchValid=false, SwFrameFormat *pParent=nullptr)
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
fill with spaces and tabs
IMPL_LINK_NOARG(SwMailMergeLayoutPage, PreviewLoadedHdl_Impl, SwOneExampleFrame &, void)
OUString GetAssignedColumn(sal_uInt32 nColumn) const
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
void Top(const tools::Long nTop)
const SwRect & GetCharRect() const
tools::Long Height() const
bool IsGreetingLine(bool bInEMail) const
OString stripStart(const OString &rIn, char c)
const OUString & GetFemaleGenderValue() const
bool IsIncludeCountry() const
constexpr TypedWhichId< SvxBoxItem > RES_BOX(106)
std::unique_ptr< weld::Container > m_xGreetingLine
virtual void Activate() override
ScXMLEditAttributeMap::Entry const aEntries[]
const SwFrameFormat * GetFlyFrameFormat() const
Get FlyFrameFormat; for UI macro linkage at Flys.
SwWrtShell * m_pExampleWrtShell
Reference< XModel > xModel
bool IsAddressBlock() const
constexpr OUStringLiteral first
void EnableKillingFile(bool bEnable=true)
bool m_bIsGreetingInserted
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
SwFrameFormat * m_pAddressBlockFormat