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 #include <iodetect.hxx>
53 
54 #include <dbui.hrc>
55 
56 using namespace osl;
57 using namespace svt;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::text;
61 using namespace ::com::sun::star::frame;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::view;
64 
65 #define DEFAULT_LEFT_DISTANCE (MM50*5) // 2,5 cm
66 #define DEFAULT_TOP_DISTANCE (MM50*11) // 5,5 cm
67 #define GREETING_TOP_DISTANCE (MM50*25) //12,5 cm
68 #define DEFAULT_ADDRESS_WIDTH (MM50*15)// 7,5 cm
69 #define DEFAULT_ADDRESS_HEIGHT (MM50*7) // 3,5cm
70 
72  : vcl::OWizardPage(pPage, pWizard, "modules/swriter/ui/mmlayoutpage.ui", "MMLayoutPage")
73  , m_pExampleWrtShell(nullptr)
74  , m_pAddressBlockFormat(nullptr)
75  , m_bIsGreetingInserted(false)
76  , m_pWizard(pWizard)
77  , m_xPosition(m_xBuilder->weld_container("addresspos"))
78  , m_xAlignToBodyCB(m_xBuilder->weld_check_button("align"))
79  , m_xLeftFT(m_xBuilder->weld_label("leftft"))
80  , m_xLeftMF(m_xBuilder->weld_metric_spin_button("left", FieldUnit::CM))
81  , m_xTopMF(m_xBuilder->weld_metric_spin_button("top", FieldUnit::CM))
82  , m_xGreetingLine(m_xBuilder->weld_container("greetingspos"))
83  , m_xUpPB(m_xBuilder->weld_button("up"))
84  , m_xDownPB(m_xBuilder->weld_button("down"))
85  , m_xZoomLB(m_xBuilder->weld_combo_box("zoom"))
86 {
87  std::shared_ptr<const SfxFilter> pSfxFlt =
88  SwDocShell::Factory().GetFilterContainer()->
89  GetFilter4FilterName("writer8", SfxFilterFlags::EXPORT);
90 
91  //save the current document into a temporary file
92  {
93  //temp file needs its own block
94  //creating with extension is not supported by a static method :-(
95  OUString const sExt(
96  comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(),'*'));
97  utl::TempFile aTempFile( OUString(), true, &sExt );
98  m_sExampleURL = aTempFile.GetURL();
99  aTempFile.EnableKillingFile();
100  }
101  SwView* pView = m_pWizard->GetSwView();
102  uno::Sequence< beans::PropertyValue > aValues(2);
103  beans::PropertyValue* pValues = aValues.getArray();
104  pValues[0].Name = "FilterName";
105  pValues[0].Value <<= pSfxFlt->GetFilterName();
106  // Don't save embedded data set! It would steal it from current document.
107  pValues[1].Name = "NoEmbDataSet";
108  pValues[1].Value <<= true;
109 
110  uno::Reference< frame::XStorable > xStore( pView->GetDocShell()->GetModel(), uno::UNO_QUERY);
111  xStore->storeToURL( m_sExampleURL, aValues );
112 
113  Link<SwOneExampleFrame&,void> aLink(LINK(this, SwMailMergeLayoutPage, PreviewLoadedHdl_Impl));
116 
117  Size aSize = m_xExampleFrame->GetDrawingArea()->get_ref_device().LogicToPixel(
118  Size(124, 159), MapMode(MapUnit::MapAppFont));
119  m_xExampleFrame->set_size_request(aSize.Width(), aSize.Height());
120 
121  m_xExampleContainerWIN->hide();
122 
123  m_xLeftMF->set_value(m_xLeftMF->normalize(DEFAULT_LEFT_DISTANCE), FieldUnit::TWIP);
124  m_xTopMF->set_value(m_xTopMF->normalize(DEFAULT_TOP_DISTANCE), FieldUnit::TWIP);
125 
127  m_xZoomLB->append_text(unicode::formatPercent(50, rLang));
128  m_xZoomLB->append_text(unicode::formatPercent(75, rLang));
129  m_xZoomLB->append_text(unicode::formatPercent(100, rLang));
130  m_xZoomLB->set_active(0); //page size
131  m_xZoomLB->connect_changed(LINK(this, SwMailMergeLayoutPage, ZoomHdl_Impl));
132 
133  Link<weld::MetricSpinButton&,void> aFrameHdl = LINK(this, SwMailMergeLayoutPage, ChangeAddressHdl_Impl);
134  m_xLeftMF->connect_value_changed(aFrameHdl);
135  m_xTopMF->connect_value_changed(aFrameHdl);
136 
137  FieldUnit eFieldUnit = ::GetDfltMetric(false);
138  ::SetFieldUnit( *m_xLeftMF, eFieldUnit );
139  ::SetFieldUnit( *m_xTopMF, eFieldUnit );
140 
141  Link<weld::Button&,void> aUpDownHdl = LINK(this, SwMailMergeLayoutPage, GreetingsHdl_Impl );
142  m_xUpPB->connect_clicked(aUpDownHdl);
143  m_xDownPB->connect_clicked(aUpDownHdl);
144  m_xAlignToBodyCB->connect_toggled(LINK(this, SwMailMergeLayoutPage, AlignToTextHdl_Impl));
145  m_xAlignToBodyCB->set_active(true);
146 }
147 
149 {
150  File::remove( m_sExampleURL );
151 }
152 
154 {
156  bool bGreetingLine = rConfigItem.IsGreetingLine(false) && !rConfigItem.IsGreetingInserted();
157  bool bAddressBlock = rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted();
158 
159  m_xPosition->set_sensitive(bAddressBlock);
160  AlignToTextHdl_Impl(*m_xAlignToBodyCB);
161 
162  m_xGreetingLine->set_sensitive(bGreetingLine);
163 
164  //check if greeting and/or address frame have to be inserted/removed
165  if(m_pExampleWrtShell) // initially there's nothing to check
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  long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
195  long nTop = static_cast< 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 }
205 
207 {
208  //now insert the frame and the greeting
210  if (eReason == ::vcl::WizardTypes::eTravelForward || eReason == ::vcl::WizardTypes::eFinish)
211  {
212  long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
213  long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
215  m_pWizard->GetSwView(),
216  rConfigItem,
217  Point(nLeft, nTop),
218  m_xAlignToBodyCB->get_active());
219  }
220  return true;
221 }
222 
224  SwMailMergeConfigItem& rConfigItem,
225  const Point& rAddressPosition,
226  bool bAlignToBody)
227 {
228  SwFrameFormat* pAddressBlockFormat = nullptr;
230  if(rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted())
231  {
232  //insert the frame
234  if(rAddressPosition.X() > 0 && rAddressPosition.Y() > 0)
235  aAddressPosition = rAddressPosition;
236  pAddressBlockFormat = InsertAddressFrame( pView->GetWrtShell(),
237  rConfigItem,
238  aAddressPosition, bAlignToBody, false);
239  rConfigItem.SetAddressInserted();
240  }
241  //now the greeting
242  if(rConfigItem.IsGreetingLine(false) && !rConfigItem.IsGreetingInserted())
243  {
244  InsertGreeting( pView->GetWrtShell(), rConfigItem, false);
245  rConfigItem.SetGreetingInserted();
246  }
248  return pAddressBlockFormat;
249 }
250 
252  SwWrtShell& rShell,
253  SwMailMergeConfigItem const & rConfigItem,
254  const Point& rDestination,
255  bool bAlignLeft,
256  bool bExample)
257 {
258  // insert the address block and the greeting line
259  SfxItemSet aSet(
260  rShell.GetAttrPool(),
261  svl::Items<
264  RES_BOX, RES_BOX>{} );
265  aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, 1));
266  if(bAlignLeft)
267  aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ));
268  else
269  aSet.Put(SwFormatHoriOrient( rDestination.X(), text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
270  aSet.Put(SwFormatVertOrient( rDestination.Y(), text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
272  // the example gets a border around the frame, the real document doesn't get one
273  if(!bExample)
274  aSet.Put(SvxBoxItem( RES_BOX ));
275  aSet.Put(SwFormatSurround( css::text::WrapTextMode_NONE ));
276 
277  rShell.NewFlyFrame(aSet, true );
278  SwFrameFormat* pRet = rShell.GetFlyFrameFormat();
279  OSL_ENSURE( pRet, "Fly not inserted" );
280 
281  rShell.UnSelectFrame();
282  const Sequence< OUString> aBlocks = rConfigItem.GetAddressBlocks();
283  if(bExample)
284  {
285  rShell.Insert(aBlocks[0]);
286  }
287  else
288  {
289  //the placeholders should be replaced by the appropriate fields
290  SwFieldMgr aFieldMgr(&rShell);
291  //create a database string source.command.commandtype.column
292  const SwDBData& rData = rConfigItem.GetCurrentDBData();
293  OUString sDBName(rData.sDataSource + OUStringChar(DB_DELIM)
294  + rData.sCommand + OUStringChar(DB_DELIM));
295  const OUString sDatabaseConditionPrefix(sDBName.replace(DB_DELIM, '.'));
296  sDBName += OUString::number(rData.nCommandType) + OUStringChar(DB_DELIM);
297 
298  // if only the country is in an address line the
299  // paragraph has to be hidden depending on the
300  // IsIncludeCountry()/GetExcludeCountry() settings
301 
302  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
303  bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs();
304  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
305  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
306 
307  const std::vector<std::pair<OUString, int>>& rHeaders = rConfigItem.GetDefaultAddressHeaders();
308  Sequence< OUString> aAssignment =
309  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
310  const OUString* pAssignment = aAssignment.getConstArray();
311  const OUString sCountryColumn(
312  (aAssignment.getLength() > MM_PART_COUNTRY && !aAssignment[MM_PART_COUNTRY].isEmpty())
313  ? aAssignment[MM_PART_COUNTRY]
314  : rHeaders[MM_PART_COUNTRY].first);
315 
316  OUString sHideParagraphsExpression;
317  SwAddressIterator aIter(aBlocks[0]);
318  while(aIter.HasMore())
319  {
320  SwMergeAddressItem aItem = aIter.Next();
321  if(aItem.bIsColumn)
322  {
323  OUString sConvertedColumn = aItem.sText;
324  auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
325  static_cast<sal_uInt32>(aAssignment.getLength()));
326  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
327  {
328  if (rHeaders[nColumn].first == aItem.sText &&
329  !pAssignment[nColumn].isEmpty())
330  {
331  sConvertedColumn = pAssignment[nColumn];
332  break;
333  }
334  }
335  const OUString sDB(sDBName + sConvertedColumn);
336 
337  if(!sHideParagraphsExpression.isEmpty())
338  sHideParagraphsExpression += " AND ";
339  sHideParagraphsExpression += "![" + sDatabaseConditionPrefix + sConvertedColumn + "]";
340 
341  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
342  {
343  // now insert a hidden paragraph field
344  if( !rExcludeCountry.isEmpty() )
345  {
346  const OUString sExpression("[" + sDatabaseConditionPrefix + sCountryColumn + "]");
348  sExpression + " != \"" + rExcludeCountry + "\"",
349  sExpression,
350  0, &rShell );
351  aFieldMgr.InsertField( aData );
352  }
353  else
354  {
356  aFieldMgr.InsertField( aData );
357  }
358  }
359  else
360  {
361  SwInsertField_Data aData(SwFieldTypesEnum::Database, 0, sDB, OUString(), 0, &rShell);
362  aFieldMgr.InsertField( aData );
363  }
364  }
365  else if(!aItem.bIsReturn)
366  {
367  rShell.Insert(aItem.sText);
368  }
369  else
370  {
371  if(bHideEmptyParagraphs)
372  {
373  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sHideParagraphsExpression, OUString(), 0, &rShell);
374  aFieldMgr.InsertField( aData );
375  }
376  sHideParagraphsExpression.clear();
377  //now add a new paragraph
378  rShell.SplitNode();
379  }
380  }
381  if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
382  {
383  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sHideParagraphsExpression, OUString(), 0, &rShell);
384  aFieldMgr.InsertField( aData );
385  }
386  }
387  return pRet;
388 }
389 
390 void SwMailMergeLayoutPage::InsertGreeting(SwWrtShell& rShell, SwMailMergeConfigItem const & rConfigItem, bool bExample)
391 {
392  //set the cursor to the desired position - if no text content is here then
393  //new paragraphs are inserted
394  const SwRect& rPageRect = rShell.GetAnyCurRect(CurRectType::Page);
395  const Point aGreetingPos( DEFAULT_LEFT_DISTANCE + rPageRect.Left(), GREETING_TOP_DISTANCE );
396 
397  const bool bRet = rShell.SetShadowCursorPos( aGreetingPos, SwFillMode::TabSpace );
398 
399  if(!bRet)
400  {
401  //there's already text at the desired position
402  //go to start of the doc, directly!
403  rShell.SttEndDoc(true);
404  //and go by paragraph until the position is reached
405  long nYPos = rShell.GetCharRect().Top();
406  while(nYPos < GREETING_TOP_DISTANCE)
407  {
408  if(!rShell.FwdPara())
409  break;
410  nYPos = rShell.GetCharRect().Top();
411  }
412  //text needs to be appended
413  while(nYPos < GREETING_TOP_DISTANCE)
414  {
415  if(!rShell.AppendTextNode())
416  break;
417  nYPos = rShell.GetCharRect().Top();
418  }
419  }
420  else
421  {
422  //we may end up inside of a paragraph if the left margin is not at DEFAULT_LEFT_DISTANCE
424  }
425  bool bSplitNode = !rShell.IsEndPara();
426  sal_Int32 nMoves = rConfigItem.GetGreetingMoves();
427  if( !bExample && 0 != nMoves )
428  {
429  if(nMoves < 0)
430  {
431  rShell.MoveParagraph( nMoves );
432  }
433  else
434  while(nMoves)
435  {
436  bool bMoved = rShell.MoveParagraph();
437  if(!bMoved)
438  {
439  //insert a new paragraph before the greeting line
440  rShell.SplitNode();
441  }
442  --nMoves;
443  }
444  }
445  //now insert the greeting text - if we have any?
446  const bool bIndividual = rConfigItem.IsIndividualGreeting(false);
447  if(bIndividual)
448  {
449  //lock expression fields - prevents hiding of the paragraph to insert into
450  rShell.LockExpFields();
451  if(bExample)
452  {
454  eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender)
455  {
457  rConfigItem.GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
458  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
459  if( nCurrent >= 0 && nCurrent < aEntries.getLength())
460  {
461  // Greeting
462  rShell.Insert(aEntries[nCurrent]);
463  break;
464  }
465  }
466  }
467  else
468  {
469  SwFieldMgr aFieldMgr(&rShell);
470  //three paragraphs, each with an appropriate hidden paragraph field
471  //are to be inserted
472 
473  //name of the gender column
474  const OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
475  const OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
476 
477  const OUString& rFemaleGenderValue = rConfigItem.GetFemaleGenderValue();
478  bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs();
479  const SwDBData& rData = rConfigItem.GetCurrentDBData();
480  const OUString sCommonBase(rData.sDataSource + "." + rData.sCommand + ".");
481  const OUString sConditionBase("[" + sCommonBase + sGenderColumn + "]");
482  const OUString sNameColumnBase("[" + sCommonBase + sNameColumn + "]");
483 
484  const OUString sDBName(rData.sDataSource + OUStringChar(DB_DELIM)
485  + rData.sCommand + OUStringChar(DB_DELIM)
486  + OUString::number(rData.nCommandType) + OUStringChar(DB_DELIM));
487 
488 // Female: [database.sGenderColumn] != "rFemaleGenderValue" && [database.NameColumn]
489 // Male: [database.sGenderColumn] == "rFemaleGenderValue" && [database.rGenderColumn]
490 // Neutral: [database.sNameColumn]
491  OSL_ENSURE(!sGenderColumn.isEmpty() && !rFemaleGenderValue.isEmpty(),
492  "gender settings not available - how to form the condition?");
493  //column used as lastname
495  eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender)
496  {
497  Sequence< OUString> aEntries = rConfigItem.GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
498  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
499  if( nCurrent >= 0 && nCurrent < aEntries.getLength())
500  {
501  const OUString sGreeting = aEntries[nCurrent];
502  OUString sCondition;
503  OUString sHideParagraphsExpression;
504  switch(eGender)
505  {
507  sCondition = sConditionBase + " != \"" + rFemaleGenderValue
508  + "\" OR NOT " + sNameColumnBase;
509  sHideParagraphsExpression = "!" + sNameColumnBase;
510  break;
512  sCondition = sConditionBase + " == \"" + rFemaleGenderValue
513  + "\" OR NOT " + sNameColumnBase;
514  break;
516  sCondition = sNameColumnBase;
517  break;
518  }
519 
520  if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
521  {
522  OUString sComplete = "(" + sCondition + ") OR (" + sHideParagraphsExpression + ")";
523  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sComplete, OUString(), 0, &rShell);
524  aFieldMgr.InsertField( aData );
525  }
526  else
527  {
528  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sCondition, OUString(), 0, &rShell);
529  aFieldMgr.InsertField( aData );
530  }
531  //now the text has to be inserted
532  const std::vector<std::pair<OUString, int>>& rHeaders = rConfigItem.GetDefaultAddressHeaders();
533  Sequence< OUString> aAssignment =
534  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
535  const OUString* pAssignment = aAssignment.getConstArray();
536  SwAddressIterator aIter(sGreeting);
537  while(aIter.HasMore())
538  {
539  SwMergeAddressItem aItem = aIter.Next();
540  if(aItem.bIsColumn)
541  {
542  OUString sConvertedColumn = aItem.sText;
543  auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
544  static_cast<sal_uInt32>(aAssignment.getLength()));
545  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
546  {
547  if (rHeaders[nColumn].first == aItem.sText &&
548  !pAssignment[nColumn].isEmpty())
549  {
550  sConvertedColumn = pAssignment[nColumn];
551  break;
552  }
553  }
555  sDBName + sConvertedColumn,
556  OUString(), 0, &rShell);
557  aFieldMgr.InsertField( aData );
558  }
559  else
560  {
561  rShell.Insert(aItem.sText);
562  }
563  }
564  //now add a new paragraph
565  rShell.SplitNode();
566  }
567  }
568 
569  }
570  rShell.UnlockExpFields();
571  }
572  else
573  {
575  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL);
576  // Greeting
577  rShell.Insert(( nCurrent >= 0 && nCurrent < aEntries.getLength() )
578  ? aEntries[nCurrent] : OUString());
579  }
580  // now insert a new paragraph here if necessary
581  if(bSplitNode)
582  {
583  rShell.Push();
584  rShell.SplitNode();
586  }
587  //put the cursor to the start of the paragraph
588  rShell.SttPara();
589 
590  OSL_ENSURE(nullptr == rShell.GetTableFormat(), "What to do with a table here?");
591 }
592 
594 {
595  m_xExampleContainerWIN->show();
596 
597  Reference< XModel > & xModel = m_xExampleFrame->GetModel();
598  //now the ViewOptions should be set properly
599  Reference< XViewSettingsSupplier > xSettings(xModel->getCurrentController(), UNO_QUERY);
600  m_xViewProperties = xSettings->getViewSettings();
601  auto pXDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(xModel);
602  SwDocShell* pDocShell = pXDoc->GetDocShell();
603  m_pExampleWrtShell = pDocShell->GetWrtShell();
604  OSL_ENSURE(m_pExampleWrtShell, "No SwWrtShell found!");
605  if(!m_pExampleWrtShell)
606  return;
607 
608  SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
609  if(rConfigItem.IsAddressBlock())
610  {
611  m_pAddressBlockFormat = InsertAddressFrame(
612  *m_pExampleWrtShell, rConfigItem,
614  m_xAlignToBodyCB->get_active(), true);
615  }
616  if(rConfigItem.IsGreetingLine(false))
617  {
618  InsertGreeting(*m_pExampleWrtShell, rConfigItem, true);
619  m_bIsGreetingInserted = true;
620  }
621 
622  ZoomHdl_Impl(*m_xZoomLB);
623 
624  const SwFormatFrameSize& rPageSize = m_pExampleWrtShell->GetPageDesc(
625  m_pExampleWrtShell->GetCurPageDesc()).GetMaster().GetFrameSize();
626  m_xLeftMF->set_max(rPageSize.GetWidth() - DEFAULT_LEFT_DISTANCE, FieldUnit::NONE);
627  m_xTopMF->set_max(rPageSize.GetHeight() - DEFAULT_TOP_DISTANCE, FieldUnit::NONE);
628 }
629 
630 IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, weld::ComboBox&, rBox, void)
631 {
632  if (m_pExampleWrtShell)
633  {
634  sal_Int16 eType = DocumentZoomType::BY_VALUE;
635  short nZoom = 50;
636  switch (rBox.get_active())
637  {
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;
642  }
643  Any aZoom;
644  aZoom <<= eType;
645  m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_TYPE, aZoom);
646  aZoom <<= nZoom;
647  m_xViewProperties->setPropertyValue(UNO_NAME_ZOOM_VALUE, aZoom);
648 
649  m_xExampleFrame->Invalidate();
650  }
651 }
652 
654 {
655  if(m_pExampleWrtShell && m_pAddressBlockFormat)
656  {
657  long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
658  long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
659 
660  SfxItemSet aSet(
661  m_pExampleWrtShell->GetAttrPool(),
663  if (m_xAlignToBodyCB->get_active())
664  aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ));
665  else
666  aSet.Put(SwFormatHoriOrient( nLeft, text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
667  aSet.Put(SwFormatVertOrient( nTop, text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
668  m_pExampleWrtShell->GetDoc()->SetFlyFrameAttr( *m_pAddressBlockFormat, aSet );
669  m_xExampleFrame->Invalidate();
670  }
671 }
672 
673 IMPL_LINK(SwMailMergeLayoutPage, GreetingsHdl_Impl, weld::Button&, rButton, void)
674 {
675  bool bDown = &rButton == m_xDownPB.get();
676  bool bMoved = m_pExampleWrtShell->MoveParagraph( bDown ? 1 : -1 );
677  if (bMoved || bDown)
678  m_pWizard->GetConfigItem().MoveGreeting(bDown ? 1 : -1 );
679  if(!bMoved && bDown)
680  {
681  //insert a new paragraph before the greeting line
682  m_pExampleWrtShell->SplitNode();
683  }
684  m_xExampleFrame->Invalidate();
685 }
686 
687 IMPL_LINK(SwMailMergeLayoutPage, AlignToTextHdl_Impl, weld::ToggleButton&, rBox, void)
688 {
689  bool bCheck = rBox.get_active() && rBox.get_sensitive();
690  m_xLeftFT->set_sensitive(!bCheck);
691  m_xLeftMF->set_sensitive(!bCheck);
692  ChangeAddressHdl_Impl( *m_xLeftMF );
693 }
694 
695 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
std::unique_ptr< weld::Button > m_xUpPB
SwMergeAddressItem Next()
bool HasMore() const
bool IsHideEmptyParagraphs() const
constexpr TypedWhichId< SwFormatSurround > RES_SURROUND(101)
bool AppendTextNode()
Definition: editsh.cxx:204
bool SttPara(bool bSelect=false)
Definition: move.cxx:352
FieldUnit
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
void SplitNode(bool bAutoFormat=false)
Definition: wrtsh1.cxx:981
bool IsAddressInserted() const
#define DEFAULT_LEFT_DISTANCE
bool DelFullPara()
Remove a complete paragraph.
Definition: eddel.cxx:345
#define UNO_NAME_ZOOM_VALUE
Definition: unoprnms.hxx:420
#define EX_SHOW_DEFAULT_PAGE
Definition: unotools.hxx:33
SwMailMergeConfigItem & GetConfigItem()
#define DEFAULT_ADDRESS_WIDTH
const char aData[]
Definition: ww8scan.hxx:47
bool SttEndDoc(bool bStt)
Definition: crsrsh.cxx:573
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1009
const LanguageTag & GetUILanguageTag() const
long Height() const
signed char sal_Int8
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
long GetWidth() const
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:89
#define UNO_NAME_ZOOM_TYPE
Definition: unoprnms.hxx:421
OUString & GetExcludeCountry() const
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:1708
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
#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.
Definition: swrect.hxx:35
bool InsertField(const SwInsertField_Data &rData)
Definition: fldmgr.cxx:889
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:292
SwWrtShell & GetWrtShell() const
Definition: view.hxx:398
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
bool GotoFly(const OUString &rName, FlyCntType eType=FLYCNTTYPE_ALL, bool bSelFrame=true)
Definition: move.cxx:594
void Top(const long nTop)
Definition: swrect.hxx:204
#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
const OUString & GetName() const
Definition: format.hxx:111
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:61
std::unique_ptr< weld::CustomWeld > m_xExampleContainerWIN
DocumentType eType
bool MovePara(SwWhichPara, SwMoveFnCollection const &)
Definition: crsrsh.cxx:695
bool IsGreetingInserted() const
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:612
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:2080
Style of a layout element.
Definition: frmfmt.hxx:57
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:687
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:2237
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
bool MoveParagraph(long nOffset=1)
Definition: ednumber.cxx:393
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:224
void UnlockExpFields()
Definition: edfld.cxx:357
std::unique_ptr< weld::CheckButton > m_xAlignToBodyCB
#define DB_DELIM
Definition: swtypes.hxx:137
SwDocShell * GetDocShell()
Definition: view.cxx:1107
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
void Left(const long nLeft)
Definition: swrect.hxx:195
const PropertyValue * pValues
bool IsIndividualGreeting(bool bInEMail) const
SwMailMergeWizard * m_pWizard
const SwFrameFormat * NewFlyFrame(const SfxItemSet &rSet, bool bAnchValid=false, SwFrameFormat *pParent=nullptr)
Definition: fefly1.cxx:642
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
const SwRect & GetCharRect() const
Definition: crsrsh.hxx:516
bool IsGreetingLine(bool bInEMail) const
void UnSelectFrame()
Definition: select.cxx:322
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.
Definition: fefly1.cxx:1244
SwWrtShell * m_pExampleWrtShell
Reference< XModel > xModel
bool IsAddressBlock() const
bool IsEndPara() const
Definition: crsrsh.cxx:1113
long GetHeight() const
bool FwdPara()
Definition: wrtsh.hxx:227
OUString sCommand
Definition: swdbdata.hxx:31
void EnableKillingFile(bool bEnable=true)
void LockExpFields()
Definition: edfld.cxx:352
Definition: view.hxx:144
constexpr TypedWhichId< SwFormatAnchor > RES_ANCHOR(104)
const char first[]
SwFrameFormat * m_pAddressBlockFormat