LibreOffice Module sw (master)  1
mmlayoutpage.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <swtypes.hxx>
21 #include "mmlayoutpage.hxx"
22 #include <mailmergewizard.hxx>
23 #include <mmconfigitem.hxx>
24 #include <mailmergehelper.hxx>
25 #include <unotools.hxx>
26 #include <comphelper/string.hxx>
27 #include <i18nutil/unicode.hxx>
28 #include <unotools/tempfile.hxx>
29 #include <uitool.hxx>
30 #include <view.hxx>
31 #include <swundo.hxx>
32 #include <sfx2/docfilt.hxx>
33 #include <sfx2/fcontnr.hxx>
34 #include <svtools/unitconv.hxx>
35 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
36 #include <com/sun/star/view/DocumentZoomType.hpp>
37 #include <fldmgr.hxx>
38 #include <fldbas.hxx>
39 #include <unotxdoc.hxx>
40 #include <docsh.hxx>
41 #include <doc.hxx>
42 #include <wrtsh.hxx>
43 #include <fmtsrnd.hxx>
44 #include <pagedesc.hxx>
45 #include <fmtanchr.hxx>
46 #include <fmtornt.hxx>
47 #include <fmtfsize.hxx>
48 #include <editeng/boxitem.hxx>
49 #include <osl/file.hxx>
50 #include <vcl/settings.hxx>
51 #include <unoprnms.hxx>
52 
53 #include <dbui.hrc>
54 
55 using namespace osl;
56 using namespace svt;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::text;
60 using namespace ::com::sun::star::frame;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::view;
63 
69 
71  : vcl::OWizardPage(pPage, pWizard, "modules/swriter/ui/mmlayoutpage.ui", "MMLayoutPage")
72  , m_pExampleWrtShell(nullptr)
73  , m_pAddressBlockFormat(nullptr)
74  , m_bIsGreetingInserted(false)
75  , m_pWizard(pWizard)
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"))
85 {
86  std::shared_ptr<const SfxFilter> pSfxFlt =
87  SwDocShell::Factory().GetFilterContainer()->
88  GetFilter4FilterName("writer8", SfxFilterFlags::EXPORT);
89 
90  //save the current document into a temporary file
91  {
92  //temp file needs its own block
93  //creating with extension is not supported by a static method :-(
94  OUString const sExt(
95  comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(),'*'));
96  utl::TempFile aTempFile( OUString(), true, &sExt );
97  m_sExampleURL = aTempFile.GetURL();
98  aTempFile.EnableKillingFile();
99  }
100  SwView* pView = m_pWizard->GetSwView();
101  uno::Sequence< beans::PropertyValue > aValues(2);
102  beans::PropertyValue* pValues = aValues.getArray();
103  pValues[0].Name = "FilterName";
104  pValues[0].Value <<= pSfxFlt->GetFilterName();
105  // Don't save embedded data set! It would steal it from current document.
106  pValues[1].Name = "NoEmbDataSet";
107  pValues[1].Value <<= true;
108 
109  uno::Reference< frame::XStorable > xStore( pView->GetDocShell()->GetModel(), uno::UNO_QUERY);
110  xStore->storeToURL( m_sExampleURL, aValues );
111 
112  Link<SwOneExampleFrame&,void> aLink(LINK(this, SwMailMergeLayoutPage, PreviewLoadedHdl_Impl));
115 
116  Size aSize = m_xExampleFrame->GetDrawingArea()->get_ref_device().LogicToPixel(
117  Size(124, 159), MapMode(MapUnit::MapAppFont));
118  m_xExampleFrame->set_size_request(aSize.Width(), aSize.Height());
119 
120  m_xExampleContainerWIN->hide();
121 
122  m_xLeftMF->set_value(m_xLeftMF->normalize(DEFAULT_LEFT_DISTANCE), FieldUnit::TWIP);
123  m_xTopMF->set_value(m_xTopMF->normalize(DEFAULT_TOP_DISTANCE), FieldUnit::TWIP);
124 
126  m_xZoomLB->append_text(unicode::formatPercent(50, rLang));
127  m_xZoomLB->append_text(unicode::formatPercent(75, rLang));
128  m_xZoomLB->append_text(unicode::formatPercent(100, rLang));
129  m_xZoomLB->set_active(0); //page size
130  m_xZoomLB->connect_changed(LINK(this, SwMailMergeLayoutPage, ZoomHdl_Impl));
131 
132  Link<weld::MetricSpinButton&,void> aFrameHdl = LINK(this, SwMailMergeLayoutPage, ChangeAddressHdl_Impl);
133  m_xLeftMF->connect_value_changed(aFrameHdl);
134  m_xTopMF->connect_value_changed(aFrameHdl);
135 
136  FieldUnit eFieldUnit = ::GetDfltMetric(false);
137  ::SetFieldUnit( *m_xLeftMF, eFieldUnit );
138  ::SetFieldUnit( *m_xTopMF, eFieldUnit );
139 
140  Link<weld::Button&,void> aUpDownHdl = LINK(this, SwMailMergeLayoutPage, GreetingsHdl_Impl );
141  m_xUpPB->connect_clicked(aUpDownHdl);
142  m_xDownPB->connect_clicked(aUpDownHdl);
143  m_xAlignToBodyCB->connect_toggled(LINK(this, SwMailMergeLayoutPage, AlignToTextHdl_Impl));
144  m_xAlignToBodyCB->set_active(true);
145 }
146 
148 {
149  File::remove( m_sExampleURL );
150 }
151 
153 {
155  bool bGreetingLine = rConfigItem.IsGreetingLine(false) && !rConfigItem.IsGreetingInserted();
156  bool bAddressBlock = rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted();
157 
158  m_xPosition->set_sensitive(bAddressBlock);
159  AlignToTextHdl_Impl(*m_xAlignToBodyCB);
160 
161  m_xGreetingLine->set_sensitive(bGreetingLine);
162 
163  //check if greeting and/or address frame have to be inserted/removed
164  if(!m_pExampleWrtShell) // initially there's nothing to check
165  return;
166 
167  if(!rConfigItem.IsGreetingInserted() &&
168  m_bIsGreetingInserted != bGreetingLine )
169  {
171  {
173  m_bIsGreetingInserted = false;
174  }
175  else
176  {
178  m_bIsGreetingInserted = true;
179  }
180  }
181  if(!rConfigItem.IsAddressInserted() &&
182  rConfigItem.IsAddressBlock() != ( nullptr != m_pAddressBlockFormat ))
183  {
185  {
189  m_pAddressBlockFormat = nullptr;
191  }
192  else
193  {
194  tools::Long nLeft = static_cast< tools::Long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
195  tools::Long nTop = static_cast< tools::Long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
198  Point(nLeft, nTop),
199  m_xAlignToBodyCB->get_active(), true);
200  }
201  }
202  m_xExampleFrame->Invalidate();
203 }
204 
206 {
207  //now insert the frame and the greeting
209  if (eReason == ::vcl::WizardTypes::eTravelForward || eReason == ::vcl::WizardTypes::eFinish)
210  {
211  tools::Long nLeft = static_cast< tools::Long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
212  tools::Long nTop = static_cast< tools::Long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
214  m_pWizard->GetSwView(),
215  rConfigItem,
216  Point(nLeft, nTop),
217  m_xAlignToBodyCB->get_active());
218  }
219  return true;
220 }
221 
223  SwMailMergeConfigItem& rConfigItem,
224  const Point& rAddressPosition,
225  bool bAlignToBody)
226 {
227  SwFrameFormat* pAddressBlockFormat = nullptr;
229  if(rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted())
230  {
231  //insert the frame
233  if(rAddressPosition.X() > 0 && rAddressPosition.Y() > 0)
234  aAddressPosition = rAddressPosition;
235  pAddressBlockFormat = InsertAddressFrame( pView->GetWrtShell(),
236  rConfigItem,
237  aAddressPosition, bAlignToBody, false);
238  rConfigItem.SetAddressInserted();
239  }
240  //now the greeting
241  if(rConfigItem.IsGreetingLine(false) && !rConfigItem.IsGreetingInserted())
242  {
243  InsertGreeting( pView->GetWrtShell(), rConfigItem, false);
244  rConfigItem.SetGreetingInserted();
245  }
247  return pAddressBlockFormat;
248 }
249 
251  SwWrtShell& rShell,
252  SwMailMergeConfigItem const & rConfigItem,
253  const Point& rDestination,
254  bool bAlignLeft,
255  bool bExample)
256 {
257  // insert the address block and the greeting line
261  RES_BOX, RES_BOX> aSet( rShell.GetAttrPool() );
262  aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, 1));
263  if(bAlignLeft)
264  aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ));
265  else
266  aSet.Put(SwFormatHoriOrient( rDestination.X(), text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
267  aSet.Put(SwFormatVertOrient( rDestination.Y(), text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
269  // the example gets a border around the frame, the real document doesn't get one
270  if(!bExample)
271  aSet.Put(SvxBoxItem( RES_BOX ));
272  aSet.Put(SwFormatSurround( css::text::WrapTextMode_NONE ));
273 
274  rShell.NewFlyFrame(aSet, true );
275  SwFrameFormat* pRet = rShell.GetFlyFrameFormat();
276  OSL_ENSURE( pRet, "Fly not inserted" );
277 
278  rShell.UnSelectFrame();
279  const Sequence< OUString> aBlocks = rConfigItem.GetAddressBlocks();
280  if(bExample)
281  {
282  rShell.Insert(aBlocks[0]);
283  }
284  else
285  {
286  //the placeholders should be replaced by the appropriate fields
287  SwFieldMgr aFieldMgr(&rShell);
288  //create a database string source.command.commandtype.column
289  const SwDBData& rData = rConfigItem.GetCurrentDBData();
290  OUString sDBName(rData.sDataSource + OUStringChar(DB_DELIM)
291  + rData.sCommand + OUStringChar(DB_DELIM));
292  const OUString sDatabaseConditionPrefix(sDBName.replace(DB_DELIM, '.'));
293  sDBName += OUString::number(rData.nCommandType) + OUStringChar(DB_DELIM);
294 
295  // if only the country is in an address line the
296  // paragraph has to be hidden depending on the
297  // IsIncludeCountry()/GetExcludeCountry() settings
298 
299  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
300  bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs();
301  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
302  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
303 
304  const std::vector<std::pair<OUString, int>>& rHeaders = rConfigItem.GetDefaultAddressHeaders();
305  Sequence< OUString> aAssignment =
306  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
307  const OUString* pAssignment = aAssignment.getConstArray();
308  const OUString sCountryColumn(
309  (aAssignment.getLength() > MM_PART_COUNTRY && !aAssignment[MM_PART_COUNTRY].isEmpty())
310  ? aAssignment[MM_PART_COUNTRY]
311  : rHeaders[MM_PART_COUNTRY].first);
312 
313  OUString sHideParagraphsExpression;
314  SwAddressIterator aIter(aBlocks[0]);
315  while(aIter.HasMore())
316  {
317  SwMergeAddressItem aItem = aIter.Next();
318  if(aItem.bIsColumn)
319  {
320  OUString sConvertedColumn = aItem.sText;
321  auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
322  static_cast<sal_uInt32>(aAssignment.getLength()));
323  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
324  {
325  if (rHeaders[nColumn].first == aItem.sText &&
326  !pAssignment[nColumn].isEmpty())
327  {
328  sConvertedColumn = pAssignment[nColumn];
329  break;
330  }
331  }
332  const OUString sDB(sDBName + sConvertedColumn);
333 
334  if(!sHideParagraphsExpression.isEmpty())
335  sHideParagraphsExpression += " AND ";
336  sHideParagraphsExpression += "![" + sDatabaseConditionPrefix + sConvertedColumn + "]";
337 
338  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
339  {
340  // now insert a hidden paragraph field
341  if( !rExcludeCountry.isEmpty() )
342  {
343  const OUString sExpression("[" + sDatabaseConditionPrefix + sCountryColumn + "]");
345  sExpression + " != \"" + rExcludeCountry + "\"",
346  sExpression,
347  0, &rShell );
348  aFieldMgr.InsertField( aData );
349  }
350  else
351  {
353  aFieldMgr.InsertField( aData );
354  }
355  }
356  else
357  {
358  SwInsertField_Data aData(SwFieldTypesEnum::Database, 0, sDB, OUString(), 0, &rShell);
359  aFieldMgr.InsertField( aData );
360  }
361  }
362  else if(!aItem.bIsReturn)
363  {
364  rShell.Insert(aItem.sText);
365  }
366  else
367  {
368  if(bHideEmptyParagraphs)
369  {
370  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sHideParagraphsExpression, OUString(), 0, &rShell);
371  aFieldMgr.InsertField( aData );
372  }
373  sHideParagraphsExpression.clear();
374  //now add a new paragraph
375  rShell.SplitNode();
376  }
377  }
378  if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
379  {
380  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sHideParagraphsExpression, OUString(), 0, &rShell);
381  aFieldMgr.InsertField( aData );
382  }
383  }
384  return pRet;
385 }
386 
387 void SwMailMergeLayoutPage::InsertGreeting(SwWrtShell& rShell, SwMailMergeConfigItem const & rConfigItem, bool bExample)
388 {
389  //set the cursor to the desired position - if no text content is here then
390  //new paragraphs are inserted
391  const SwRect& rPageRect = rShell.GetAnyCurRect(CurRectType::Page);
392  const Point aGreetingPos( DEFAULT_LEFT_DISTANCE + rPageRect.Left(), GREETING_TOP_DISTANCE );
393 
394  const bool bRet = rShell.SetShadowCursorPos( aGreetingPos, SwFillMode::TabSpace );
395 
396  if(!bRet)
397  {
398  //there's already text at the desired position
399  //go to start of the doc, directly!
400  rShell.SttEndDoc(true);
401  //and go by paragraph until the position is reached
402  tools::Long nYPos = rShell.GetCharRect().Top();
403  while(nYPos < GREETING_TOP_DISTANCE)
404  {
405  if(!rShell.FwdPara())
406  break;
407  nYPos = rShell.GetCharRect().Top();
408  }
409  //text needs to be appended
410  while(nYPos < GREETING_TOP_DISTANCE)
411  {
412  if(!rShell.AppendTextNode())
413  break;
414  nYPos = rShell.GetCharRect().Top();
415  }
416  }
417  else
418  {
419  //we may end up inside of a paragraph if the left margin is not at DEFAULT_LEFT_DISTANCE
421  }
422  bool bSplitNode = !rShell.IsEndPara();
423  sal_Int32 nMoves = rConfigItem.GetGreetingMoves();
424  if( !bExample && 0 != nMoves )
425  {
426  if(nMoves < 0)
427  {
428  rShell.MoveParagraph( nMoves );
429  }
430  else
431  while(nMoves)
432  {
433  bool bMoved = rShell.MoveParagraph();
434  if(!bMoved)
435  {
436  //insert a new paragraph before the greeting line
437  rShell.SplitNode();
438  }
439  --nMoves;
440  }
441  }
442  //now insert the greeting text - if we have any?
443  const bool bIndividual = rConfigItem.IsIndividualGreeting(false);
444  if(bIndividual)
445  {
446  //lock expression fields - prevents hiding of the paragraph to insert into
447  rShell.LockExpFields();
448  if(bExample)
449  {
451  eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender)
452  {
454  rConfigItem.GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
455  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
456  if( nCurrent >= 0 && nCurrent < aEntries.getLength())
457  {
458  // Greeting
459  rShell.Insert(aEntries[nCurrent]);
460  break;
461  }
462  }
463  }
464  else
465  {
466  SwFieldMgr aFieldMgr(&rShell);
467  //three paragraphs, each with an appropriate hidden paragraph field
468  //are to be inserted
469 
470  //name of the gender column
471  const OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
472  const OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
473 
474  const OUString& rFemaleGenderValue = rConfigItem.GetFemaleGenderValue();
475  bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs();
476  const SwDBData& rData = rConfigItem.GetCurrentDBData();
477  const OUString sCommonBase(rData.sDataSource + "." + rData.sCommand + ".");
478  const OUString sConditionBase("[" + sCommonBase + sGenderColumn + "]");
479  const OUString sNameColumnBase("[" + sCommonBase + sNameColumn + "]");
480 
481  const OUString sDBName(rData.sDataSource + OUStringChar(DB_DELIM)
482  + rData.sCommand + OUStringChar(DB_DELIM)
483  + OUString::number(rData.nCommandType) + OUStringChar(DB_DELIM));
484 
485 // Female: [database.sGenderColumn] != "rFemaleGenderValue" && [database.NameColumn]
486 // Male: [database.sGenderColumn] == "rFemaleGenderValue" && [database.rGenderColumn]
487 // Neutral: [database.sNameColumn]
488  OSL_ENSURE(!sGenderColumn.isEmpty() && !rFemaleGenderValue.isEmpty(),
489  "gender settings not available - how to form the condition?");
490  //column used as lastname
492  eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender)
493  {
494  Sequence< OUString> aEntries = rConfigItem.GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
495  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
496  if( nCurrent >= 0 && nCurrent < aEntries.getLength())
497  {
498  const OUString sGreeting = aEntries[nCurrent];
499  OUString sCondition;
500  OUString sHideParagraphsExpression;
501  switch(eGender)
502  {
504  sCondition = sConditionBase + " != \"" + rFemaleGenderValue
505  + "\" OR NOT " + sNameColumnBase;
506  sHideParagraphsExpression = "!" + sNameColumnBase;
507  break;
509  sCondition = sConditionBase + " == \"" + rFemaleGenderValue
510  + "\" OR NOT " + sNameColumnBase;
511  break;
513  sCondition = sNameColumnBase;
514  break;
515  }
516 
517  if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
518  {
519  OUString sComplete = "(" + sCondition + ") OR (" + sHideParagraphsExpression + ")";
520  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sComplete, OUString(), 0, &rShell);
521  aFieldMgr.InsertField( aData );
522  }
523  else
524  {
525  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sCondition, OUString(), 0, &rShell);
526  aFieldMgr.InsertField( aData );
527  }
528  //now the text has to be inserted
529  const std::vector<std::pair<OUString, int>>& rHeaders = rConfigItem.GetDefaultAddressHeaders();
530  Sequence< OUString> aAssignment =
531  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
532  const OUString* pAssignment = aAssignment.getConstArray();
533  SwAddressIterator aIter(sGreeting);
534  while(aIter.HasMore())
535  {
536  SwMergeAddressItem aItem = aIter.Next();
537  if(aItem.bIsColumn)
538  {
539  OUString sConvertedColumn = aItem.sText;
540  auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
541  static_cast<sal_uInt32>(aAssignment.getLength()));
542  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
543  {
544  if (rHeaders[nColumn].first == aItem.sText &&
545  !pAssignment[nColumn].isEmpty())
546  {
547  sConvertedColumn = pAssignment[nColumn];
548  break;
549  }
550  }
552  sDBName + sConvertedColumn,
553  OUString(), 0, &rShell);
554  aFieldMgr.InsertField( aData );
555  }
556  else
557  {
558  rShell.Insert(aItem.sText);
559  }
560  }
561  //now add a new paragraph
562  rShell.SplitNode();
563  }
564  }
565 
566  }
567  rShell.UnlockExpFields();
568  }
569  else
570  {
572  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL);
573  // Greeting
574  rShell.Insert(( nCurrent >= 0 && nCurrent < aEntries.getLength() )
575  ? aEntries[nCurrent] : OUString());
576  }
577  // now insert a new paragraph here if necessary
578  if(bSplitNode)
579  {
580  rShell.Push();
581  rShell.SplitNode();
583  }
584  //put the cursor to the start of the paragraph
585  rShell.SttPara();
586 
587  OSL_ENSURE(nullptr == rShell.GetTableFormat(), "What to do with a table here?");
588 }
589 
591 {
592  m_xExampleContainerWIN->show();
593 
594  Reference< XModel > & xModel = m_xExampleFrame->GetModel();
595  //now the ViewOptions should be set properly
596  Reference< XViewSettingsSupplier > xSettings(xModel->getCurrentController(), UNO_QUERY);
597  m_xViewProperties = xSettings->getViewSettings();
598  auto pXDoc = comphelper::getFromUnoTunnel<SwXTextDocument>(xModel);
599  SwDocShell* pDocShell = pXDoc->GetDocShell();
600  m_pExampleWrtShell = pDocShell->GetWrtShell();
601  OSL_ENSURE(m_pExampleWrtShell, "No SwWrtShell found!");
602  if(!m_pExampleWrtShell)
603  return;
604 
605  SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
606  if(rConfigItem.IsAddressBlock())
607  {
608  m_pAddressBlockFormat = InsertAddressFrame(
609  *m_pExampleWrtShell, rConfigItem,
611  m_xAlignToBodyCB->get_active(), true);
612  }
613  if(rConfigItem.IsGreetingLine(false))
614  {
615  InsertGreeting(*m_pExampleWrtShell, rConfigItem, true);
616  m_bIsGreetingInserted = true;
617  }
618 
619  ZoomHdl_Impl(*m_xZoomLB);
620 
621  const SwFormatFrameSize& rPageSize = m_pExampleWrtShell->GetPageDesc(
622  m_pExampleWrtShell->GetCurPageDesc()).GetMaster().GetFrameSize();
623  m_xLeftMF->set_max(rPageSize.GetWidth() - DEFAULT_LEFT_DISTANCE, FieldUnit::NONE);
624  m_xTopMF->set_max(rPageSize.GetHeight() - DEFAULT_TOP_DISTANCE, FieldUnit::NONE);
625 }
626 
627 IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, weld::ComboBox&, rBox, void)
628 {
629  if (!m_pExampleWrtShell)
630  return;
631 
632  sal_Int16 eType = DocumentZoomType::BY_VALUE;
633  short nZoom = 50;
634  switch (rBox.get_active())
635  {
636  case 0 : eType = DocumentZoomType::ENTIRE_PAGE; break;
637  case 1 : nZoom = 50; break;
638  case 2 : nZoom = 75; break;
639  case 3 : nZoom = 100; break;
640  }
641  Any aZoom;
642  aZoom <<= eType;
643  m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
644  aZoom <<= nZoom;
645  m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom);
646 
647  m_xExampleFrame->Invalidate();
648 }
649 
651 {
652  if(!(m_pExampleWrtShell && m_pAddressBlockFormat))
653  return;
654 
655  tools::Long nLeft = static_cast< tools::Long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
656  tools::Long nTop = static_cast< tools::Long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
657 
659  m_pExampleWrtShell->GetAttrPool());
660  if (m_xAlignToBodyCB->get_active())
661  aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ));
662  else
663  aSet.Put(SwFormatHoriOrient( nLeft, text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
664  aSet.Put(SwFormatVertOrient( nTop, text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
665  m_pExampleWrtShell->GetDoc()->SetFlyFrameAttr( *m_pAddressBlockFormat, aSet );
666  m_xExampleFrame->Invalidate();
667 }
668 
669 IMPL_LINK(SwMailMergeLayoutPage, GreetingsHdl_Impl, weld::Button&, rButton, void)
670 {
671  bool bDown = &rButton == m_xDownPB.get();
672  bool bMoved = m_pExampleWrtShell->MoveParagraph( bDown ? 1 : -1 );
673  if (bMoved || bDown)
674  m_pWizard->GetConfigItem().MoveGreeting(bDown ? 1 : -1 );
675  if(!bMoved && bDown)
676  {
677  //insert a new paragraph before the greeting line
678  m_pExampleWrtShell->SplitNode();
679  }
680  m_xExampleFrame->Invalidate();
681 }
682 
683 IMPL_LINK(SwMailMergeLayoutPage, AlignToTextHdl_Impl, weld::Toggleable&, rBox, void)
684 {
685  bool bCheck = rBox.get_active() && rBox.get_sensitive();
686  m_xLeftFT->set_sensitive(!bCheck);
687  m_xLeftMF->set_sensitive(!bCheck);
688  ChangeAddressHdl_Impl( *m_xLeftMF );
689 }
690 
691 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xUpPB
SwMergeAddressItem Next()
bool HasMore() const
bool IsHideEmptyParagraphs() const
tools::Long GetWidth() const
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
bool AppendTextNode()
Definition: editsh.cxx:205
bool SttPara(bool bSelect=false)
Definition: move.cxx:356
FieldUnit
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
void SplitNode(bool bAutoFormat=false)
Definition: wrtsh1.cxx:1001
bool IsAddressInserted() const
bool DelFullPara()
Remove a complete paragraph.
Definition: eddel.cxx:342
#define UNO_NAME_ZOOM_VALUE
Definition: unoprnms.hxx:422
#define EX_SHOW_DEFAULT_PAGE
Definition: unotools.hxx:37
SwMailMergeConfigItem & GetConfigItem()
constexpr auto toTwips(N number, Length from)
bool SttEndDoc(bool bStt)
Definition: crsrsh.cxx:574
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1016
const LanguageTag & GetUILanguageTag() const
signed char sal_Int8
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
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
Definition: fews.cxx:90
#define UNO_NAME_ZOOM_TYPE
Definition: unoprnms.hxx:423
OUString & GetExcludeCountry() const
long Long
OUString sDataSource
Definition: swdbdata.hxx:30
static const AllSettings & GetSettings()
std::unique_ptr< SwOneExampleFrame > m_xExampleFrame
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1729
constexpr tools::Long GREETING_TOP_DISTANCE
css::uno::Reference< css::frame::XModel3 > GetModel() const
SwMoveFnCollection const & fnParaStart
Definition: paminit.cxx:46
const ContentProperties & rData
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
const SwDBData & GetCurrentDBData() const
constexpr tools::Long DEFAULT_ADDRESS_WIDTH
sal_Int32 GetGreetingMoves() const
std::unique_ptr< weld::Builder > m_xBuilder
std::unique_ptr< weld::MetricSpinButton > m_xLeftMF
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
bool InsertField(const SwInsertField_Data &rData)
Definition: fldmgr.cxx:894
Value in Var-direction gives minimum (can be exceeded but not be less).
std::unique_ptr< weld::ComboBox > m_xZoomLB
bool DelRight()
Definition: delete.cxx:295
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
constexpr tools::Long Width() const
bool GotoFly(const OUString &rName, FlyCntType eType=FLYCNTTYPE_ALL, bool bSelFrame=true)
Definition: move.cxx:599
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)
const OUString & GetName() const
Definition: format.hxx:115
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)
Definition: wrtsh2.cxx:62
bool MoveParagraph(tools::Long nOffset=1)
Definition: ednumber.cxx:397
std::unique_ptr< weld::CustomWeld > m_xExampleContainerWIN
constexpr OUStringLiteral aData
Definition: ww8scan.hxx:48
DocumentType eType
bool MovePara(SwWhichPara, SwMoveFnCollection const &)
Definition: crsrsh.cxx:696
bool IsGreetingInserted() const
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:613
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)
Definition: crstrvl.cxx:2076
Style of a layout element.
Definition: frmfmt.hxx:59
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:763
OUString const & GetURL() const
std::unique_ptr< weld::Button > m_xDownPB
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2240
std::unique_ptr< weld::Container > m_xPosition
FlyAnchors.
Definition: fmtanchr.hxx:34
virtual ~SwMailMergeLayoutPage() override
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
constexpr tools::Long DEFAULT_LEFT_DISTANCE
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:224
tools::Long GetHeight() const
void UnlockExpFields()
Definition: edfld.cxx:347
std::unique_ptr< weld::CheckButton > m_xAlignToBodyCB
#define DB_DELIM
Definition: swtypes.hxx:131
SwDocShell * GetDocShell()
Definition: view.cxx:1127
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:183
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
Rect of current page.
sal_Int32 GetCurrentGreeting(Gender eType) const
std::unique_ptr< weld::MetricSpinButton > m_xTopMF
const PropertyValue * pValues
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr tools::Long DEFAULT_TOP_DISTANCE
bool IsIndividualGreeting(bool bInEMail) const
SwMailMergeWizard * m_pWizard
const SwFrameFormat * NewFlyFrame(const SfxItemSet &rSet, bool bAnchValid=false, SwFrameFormat *pParent=nullptr)
Definition: fefly1.cxx:660
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
constexpr tools::Long Height() const
OString stripStart(std::string_view rIn, char c)
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)
Definition: swrect.hxx:206
const SwRect & GetCharRect() const
Definition: crsrsh.hxx:516
bool IsGreetingLine(bool bInEMail) const
void UnSelectFrame()
Definition: select.cxx:323
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.
Definition: fefly1.cxx:1272
SwWrtShell * m_pExampleWrtShell
constexpr tools::Long DEFAULT_ADDRESS_HEIGHT
Reference< XModel > xModel
bool IsAddressBlock() const
bool IsEndPara() const
Definition: crsrsh.cxx:1114
constexpr OUStringLiteral first
bool FwdPara()
Definition: wrtsh.hxx:230
OUString sCommand
Definition: swdbdata.hxx:31
void EnableKillingFile(bool bEnable=true)
void LockExpFields()
Definition: edfld.cxx:342
Definition: view.hxx:144
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
SwFrameFormat * m_pAddressBlockFormat