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 <svtools/unitconv.hxx>
34 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
35 #include <com/sun/star/view/DocumentZoomType.hpp>
36 #include <fldmgr.hxx>
37 #include <fldbas.hxx>
38 #include <unotxdoc.hxx>
39 #include <docsh.hxx>
40 #include <doc.hxx>
41 #include <wrtsh.hxx>
42 #include <fmtsrnd.hxx>
43 #include <pagedesc.hxx>
44 #include <fmtanchr.hxx>
45 #include <fmtornt.hxx>
46 #include <fmtfsize.hxx>
47 #include <editeng/boxitem.hxx>
48 #include <osl/file.hxx>
49 #include <vcl/settings.hxx>
50 #include <unoprnms.hxx>
51 #include <iodetect.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 
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
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 = SwIoSystem::GetFilterOfFormat(
87  FILTER_XML,
88  SwDocShell::Factory().GetFilterContainer() );
89  //save the current document into a temporary file
90  {
91  //temp file needs its own block
92  //creating with extension is not supported by a static method :-(
93  OUString const sExt(
94  comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(),'*'));
95  utl::TempFile aTempFile( OUString(), true, &sExt );
96  m_sExampleURL = aTempFile.GetURL();
97  aTempFile.EnableKillingFile();
98  }
99  SwView* pView = m_pWizard->GetSwView();
100  uno::Sequence< beans::PropertyValue > aValues(2);
101  beans::PropertyValue* pValues = aValues.getArray();
102  pValues[0].Name = "FilterName";
103  pValues[0].Value <<= pSfxFlt->GetFilterName();
104  // Don't save embedded data set! It would steal it from current document.
105  pValues[1].Name = "NoEmbDataSet";
106  pValues[1].Value <<= true;
107 
108  uno::Reference< frame::XStorable > xStore( pView->GetDocShell()->GetModel(), uno::UNO_QUERY);
109  xStore->storeToURL( m_sExampleURL, aValues );
110 
111  Link<SwOneExampleFrame&,void> aLink(LINK(this, SwMailMergeLayoutPage, PreviewLoadedHdl_Impl));
114 
115  Size aSize = m_xExampleFrame->GetDrawingArea()->get_ref_device().LogicToPixel(
116  Size(124, 159), MapMode(MapUnit::MapAppFont));
117  m_xExampleFrame->set_size_request(aSize.Width(), aSize.Height());
118 
119  m_xExampleContainerWIN->hide();
120 
121  m_xLeftMF->set_value(m_xLeftMF->normalize(DEFAULT_LEFT_DISTANCE), FieldUnit::TWIP);
122  m_xTopMF->set_value(m_xTopMF->normalize(DEFAULT_TOP_DISTANCE), FieldUnit::TWIP);
123 
125  m_xZoomLB->append_text(unicode::formatPercent(50, rLang));
126  m_xZoomLB->append_text(unicode::formatPercent(75, rLang));
127  m_xZoomLB->append_text(unicode::formatPercent(100, rLang));
128  m_xZoomLB->set_active(0); //page size
129  m_xZoomLB->connect_changed(LINK(this, SwMailMergeLayoutPage, ZoomHdl_Impl));
130 
131  Link<weld::MetricSpinButton&,void> aFrameHdl = LINK(this, SwMailMergeLayoutPage, ChangeAddressHdl_Impl);
132  m_xLeftMF->connect_value_changed(aFrameHdl);
133  m_xTopMF->connect_value_changed(aFrameHdl);
134 
135  FieldUnit eFieldUnit = ::GetDfltMetric(false);
136  ::SetFieldUnit( *m_xLeftMF, eFieldUnit );
137  ::SetFieldUnit( *m_xTopMF, eFieldUnit );
138 
139  Link<weld::Button&,void> aUpDownHdl = LINK(this, SwMailMergeLayoutPage, GreetingsHdl_Impl );
140  m_xUpPB->connect_clicked(aUpDownHdl);
141  m_xDownPB->connect_clicked(aUpDownHdl);
142  m_xAlignToBodyCB->connect_toggled(LINK(this, SwMailMergeLayoutPage, AlignToTextHdl_Impl));
143  m_xAlignToBodyCB->set_active(true);
144 }
145 
147 {
148  File::remove( m_sExampleURL );
149 }
150 
152 {
154  bool bGreetingLine = rConfigItem.IsGreetingLine(false) && !rConfigItem.IsGreetingInserted();
155  bool bAddressBlock = rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted();
156 
157  m_xPosition->set_sensitive(bAddressBlock);
158  AlignToTextHdl_Impl(*m_xAlignToBodyCB);
159 
160  m_xGreetingLine->set_sensitive(bGreetingLine);
161 
162  //check if greeting and/or address frame have to be inserted/removed
163  if(m_pExampleWrtShell) // initially there's nothing to check
164  {
165  if(!rConfigItem.IsGreetingInserted() &&
166  m_bIsGreetingInserted != bGreetingLine )
167  {
169  {
171  m_bIsGreetingInserted = false;
172  }
173  else
174  {
176  m_bIsGreetingInserted = true;
177  }
178  }
179  if(!rConfigItem.IsAddressInserted() &&
180  rConfigItem.IsAddressBlock() != ( nullptr != m_pAddressBlockFormat ))
181  {
183  {
187  m_pAddressBlockFormat = nullptr;
189  }
190  else
191  {
192  long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
193  long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
196  Point(nLeft, nTop),
197  m_xAlignToBodyCB->get_active(), true);
198  }
199  }
200  m_xExampleFrame->Invalidate();
201  }
202 }
203 
205 {
206  //now insert the frame and the greeting
208  if (eReason == ::vcl::WizardTypes::eTravelForward || eReason == ::vcl::WizardTypes::eFinish)
209  {
210  long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
211  long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
213  m_pWizard->GetSwView(),
214  rConfigItem,
215  Point(nLeft, nTop),
216  m_xAlignToBodyCB->get_active());
217  }
218  return true;
219 }
220 
222  SwMailMergeConfigItem& rConfigItem,
223  const Point& rAddressPosition,
224  bool bAlignToBody)
225 {
226  SwFrameFormat* pAddressBlockFormat = nullptr;
228  if(rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted())
229  {
230  //insert the frame
232  if(rAddressPosition.X() > 0 && rAddressPosition.Y() > 0)
233  aAddressPosition = rAddressPosition;
234  pAddressBlockFormat = InsertAddressFrame( pView->GetWrtShell(),
235  rConfigItem,
236  aAddressPosition, bAlignToBody, false);
237  rConfigItem.SetAddressInserted();
238  }
239  //now the greeting
240  if(rConfigItem.IsGreetingLine(false) && !rConfigItem.IsGreetingInserted())
241  {
242  InsertGreeting( pView->GetWrtShell(), rConfigItem, false);
243  rConfigItem.SetGreetingInserted();
244  }
246  return pAddressBlockFormat;
247 }
248 
250  SwWrtShell& rShell,
251  SwMailMergeConfigItem const & rConfigItem,
252  const Point& rDestination,
253  bool bAlignLeft,
254  bool bExample)
255 {
256  // insert the address block and the greeting line
257  SfxItemSet aSet(
258  rShell.GetAttrPool(),
259  svl::Items<
262  RES_BOX, RES_BOX>{} );
263  aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, 1));
264  if(bAlignLeft)
265  aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ));
266  else
267  aSet.Put(SwFormatHoriOrient( rDestination.X(), text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
268  aSet.Put(SwFormatVertOrient( rDestination.Y(), text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
270  // the example gets a border around the frame, the real document doesn't get one
271  if(!bExample)
272  aSet.Put(SvxBoxItem( RES_BOX ));
273  aSet.Put(SwFormatSurround( css::text::WrapTextMode_NONE ));
274 
275  rShell.NewFlyFrame(aSet, true );
276  SwFrameFormat* pRet = rShell.GetFlyFrameFormat();
277  OSL_ENSURE( pRet, "Fly not inserted" );
278 
279  rShell.UnSelectFrame();
280  const Sequence< OUString> aBlocks = rConfigItem.GetAddressBlocks();
281  if(bExample)
282  {
283  rShell.Insert(aBlocks[0]);
284  }
285  else
286  {
287  //the placeholders should be replaced by the appropriate fields
288  SwFieldMgr aFieldMgr(&rShell);
289  //create a database string source.command.commandtype.column
290  const SwDBData& rData = rConfigItem.GetCurrentDBData();
291  OUString sDBName(rData.sDataSource + OUStringChar(DB_DELIM)
292  + rData.sCommand + OUStringChar(DB_DELIM));
293  const OUString sDatabaseConditionPrefix(sDBName.replace(DB_DELIM, '.'));
294  sDBName += OUString::number(rData.nCommandType) + OUStringChar(DB_DELIM);
295 
296  // if only the country is in an address line the
297  // paragraph has to be hidden depending on the
298  // IsIncludeCountry()/GetExcludeCountry() settings
299 
300  bool bIncludeCountry = rConfigItem.IsIncludeCountry();
301  bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs();
302  const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
303  bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
304 
305  const std::vector<std::pair<OUString, int>>& rHeaders = rConfigItem.GetDefaultAddressHeaders();
306  Sequence< OUString> aAssignment =
307  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
308  const OUString* pAssignment = aAssignment.getConstArray();
309  const OUString sCountryColumn(
310  (aAssignment.getLength() > MM_PART_COUNTRY && !aAssignment[MM_PART_COUNTRY].isEmpty())
311  ? aAssignment[MM_PART_COUNTRY]
312  : rHeaders[MM_PART_COUNTRY].first);
313 
314  OUString sHideParagraphsExpression;
315  SwAddressIterator aIter(aBlocks[0]);
316  while(aIter.HasMore())
317  {
318  SwMergeAddressItem aItem = aIter.Next();
319  if(aItem.bIsColumn)
320  {
321  OUString sConvertedColumn = aItem.sText;
322  auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
323  static_cast<sal_uInt32>(aAssignment.getLength()));
324  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
325  {
326  if (rHeaders[nColumn].first == aItem.sText &&
327  !pAssignment[nColumn].isEmpty())
328  {
329  sConvertedColumn = pAssignment[nColumn];
330  break;
331  }
332  }
333  const OUString sDB(sDBName + sConvertedColumn);
334 
335  if(!sHideParagraphsExpression.isEmpty())
336  sHideParagraphsExpression += " AND ";
337  sHideParagraphsExpression += "![" + sDatabaseConditionPrefix + sConvertedColumn + "]";
338 
339  if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
340  {
341  // now insert a hidden paragraph field
342  if( !rExcludeCountry.isEmpty() )
343  {
344  const OUString sExpression("[" + sDatabaseConditionPrefix + sCountryColumn + "]");
346  sExpression + " != \"" + rExcludeCountry + "\"",
347  sExpression,
348  0, &rShell );
349  aFieldMgr.InsertField( aData );
350  }
351  else
352  {
354  aFieldMgr.InsertField( aData );
355  }
356  }
357  else
358  {
359  SwInsertField_Data aData(SwFieldTypesEnum::Database, 0, sDB, OUString(), 0, &rShell);
360  aFieldMgr.InsertField( aData );
361  }
362  }
363  else if(!aItem.bIsReturn)
364  {
365  rShell.Insert(aItem.sText);
366  }
367  else
368  {
369  if(bHideEmptyParagraphs)
370  {
371  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sHideParagraphsExpression, OUString(), 0, &rShell);
372  aFieldMgr.InsertField( aData );
373  }
374  sHideParagraphsExpression.clear();
375  //now add a new paragraph
376  rShell.SplitNode();
377  }
378  }
379  if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
380  {
381  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sHideParagraphsExpression, OUString(), 0, &rShell);
382  aFieldMgr.InsertField( aData );
383  }
384  }
385  return pRet;
386 }
387 
388 void SwMailMergeLayoutPage::InsertGreeting(SwWrtShell& rShell, SwMailMergeConfigItem const & rConfigItem, bool bExample)
389 {
390  //set the cursor to the desired position - if no text content is here then
391  //new paragraphs are inserted
392  const SwRect& rPageRect = rShell.GetAnyCurRect(CurRectType::Page);
393  const Point aGreetingPos( DEFAULT_LEFT_DISTANCE + rPageRect.Left(), GREETING_TOP_DISTANCE );
394 
395  const bool bRet = rShell.SetShadowCursorPos( aGreetingPos, FILL_TAB_SPACE );
396 
397  if(!bRet)
398  {
399  //there's already text at the desired position
400  //go to start of the doc, directly!
401  rShell.SttEndDoc(true);
402  //and go by paragraph until the position is reached
403  long nYPos = rShell.GetCharRect().Top();
404  while(nYPos < GREETING_TOP_DISTANCE)
405  {
406  if(!rShell.FwdPara())
407  break;
408  nYPos = rShell.GetCharRect().Top();
409  }
410  //text needs to be appended
411  while(nYPos < GREETING_TOP_DISTANCE)
412  {
413  if(!rShell.AppendTextNode())
414  break;
415  nYPos = rShell.GetCharRect().Top();
416  }
417  }
418  else
419  {
420  //we may end up inside of a paragraph if the left margin is not at DEFAULT_LEFT_DISTANCE
422  }
423  bool bSplitNode = !rShell.IsEndPara();
424  sal_Int32 nMoves = rConfigItem.GetGreetingMoves();
425  if( !bExample && 0 != nMoves )
426  {
427  if(nMoves < 0)
428  {
429  rShell.MoveParagraph( nMoves );
430  }
431  else
432  while(nMoves)
433  {
434  bool bMoved = rShell.MoveParagraph();
435  if(!bMoved)
436  {
437  //insert a new paragraph before the greeting line
438  rShell.SplitNode();
439  }
440  --nMoves;
441  }
442  }
443  //now insert the greeting text - if we have any?
444  const bool bIndividual = rConfigItem.IsIndividualGreeting(false);
445  if(bIndividual)
446  {
447  //lock expression fields - prevents hiding of the paragraph to insert into
448  rShell.LockExpFields();
449  if(bExample)
450  {
452  eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender)
453  {
455  rConfigItem.GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
456  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
457  if( nCurrent >= 0 && nCurrent < aEntries.getLength())
458  {
459  // Greeting
460  rShell.Insert(aEntries[nCurrent]);
461  break;
462  }
463  }
464  }
465  else
466  {
467  SwFieldMgr aFieldMgr(&rShell);
468  //three paragraphs, each with an appropriate hidden paragraph field
469  //are to be inserted
470 
471  //name of the gender column
472  const OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
473  const OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
474 
475  const OUString& rFemaleGenderValue = rConfigItem.GetFemaleGenderValue();
476  bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs();
477  const SwDBData& rData = rConfigItem.GetCurrentDBData();
478  const OUString sCommonBase(rData.sDataSource + "." + rData.sCommand + ".");
479  const OUString sConditionBase("[" + sCommonBase + sGenderColumn + "]");
480  const OUString sNameColumnBase("[" + sCommonBase + sNameColumn + "]");
481 
482  const OUString sDBName(rData.sDataSource + OUStringChar(DB_DELIM)
483  + rData.sCommand + OUStringChar(DB_DELIM)
484  + OUString::number(rData.nCommandType) + OUStringChar(DB_DELIM));
485 
486 // Female: [database.sGenderColumn] != "rFemaleGenderValue" && [database.NameColumn]
487 // Male: [database.sGenderColumn] == "rFemaleGenderValue" && [database.rGenderColumn]
488 // Neutral: [database.sNameColumn]
489  OSL_ENSURE(!sGenderColumn.isEmpty() && !rFemaleGenderValue.isEmpty(),
490  "gender settings not available - how to form the condition?");
491  //column used as lastname
493  eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender)
494  {
495  Sequence< OUString> aEntries = rConfigItem.GetGreetings(static_cast<SwMailMergeConfigItem::Gender>(eGender));
496  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(static_cast<SwMailMergeConfigItem::Gender>(eGender));
497  if( nCurrent >= 0 && nCurrent < aEntries.getLength())
498  {
499  const OUString sGreeting = aEntries[nCurrent];
500  OUString sCondition;
501  OUString sHideParagraphsExpression;
502  switch(eGender)
503  {
505  sCondition = sConditionBase + " != \"" + rFemaleGenderValue
506  + "\" OR NOT " + sNameColumnBase;
507  sHideParagraphsExpression = "!" + sNameColumnBase;
508  break;
510  sCondition = sConditionBase + " == \"" + rFemaleGenderValue
511  + "\" OR NOT " + sNameColumnBase;
512  break;
514  sCondition = sNameColumnBase;
515  break;
516  }
517 
518  if(bHideEmptyParagraphs && !sHideParagraphsExpression.isEmpty())
519  {
520  OUString sComplete = "(" + sCondition + ") OR (" + sHideParagraphsExpression + ")";
521  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sComplete, OUString(), 0, &rShell);
522  aFieldMgr.InsertField( aData );
523  }
524  else
525  {
526  SwInsertField_Data aData(SwFieldTypesEnum::HiddenParagraph, 0, sCondition, OUString(), 0, &rShell);
527  aFieldMgr.InsertField( aData );
528  }
529  //now the text has to be inserted
530  const std::vector<std::pair<OUString, int>>& rHeaders = rConfigItem.GetDefaultAddressHeaders();
531  Sequence< OUString> aAssignment =
532  rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
533  const OUString* pAssignment = aAssignment.getConstArray();
534  SwAddressIterator aIter(sGreeting);
535  while(aIter.HasMore())
536  {
537  SwMergeAddressItem aItem = aIter.Next();
538  if(aItem.bIsColumn)
539  {
540  OUString sConvertedColumn = aItem.sText;
541  auto nSize = std::min(static_cast<sal_uInt32>(rHeaders.size()),
542  static_cast<sal_uInt32>(aAssignment.getLength()));
543  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
544  {
545  if (rHeaders[nColumn].first == aItem.sText &&
546  !pAssignment[nColumn].isEmpty())
547  {
548  sConvertedColumn = pAssignment[nColumn];
549  break;
550  }
551  }
553  sDBName + sConvertedColumn,
554  OUString(), 0, &rShell);
555  aFieldMgr.InsertField( aData );
556  }
557  else
558  {
559  rShell.Insert(aItem.sText);
560  }
561  }
562  //now add a new paragraph
563  rShell.SplitNode();
564  }
565  }
566 
567  }
568  rShell.UnlockExpFields();
569  }
570  else
571  {
573  sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL);
574  // Greeting
575  rShell.Insert(( nCurrent >= 0 && nCurrent < aEntries.getLength() )
576  ? aEntries[nCurrent] : OUString());
577  }
578  // now insert a new paragraph here if necessary
579  if(bSplitNode)
580  {
581  rShell.Push();
582  rShell.SplitNode();
584  }
585  //put the cursor to the start of the paragraph
586  rShell.SttPara();
587 
588  OSL_ENSURE(nullptr == rShell.GetTableFormat(), "What to do with a table here?");
589 }
590 
592 {
593  m_xExampleContainerWIN->show();
594 
595  Reference< XModel > & xModel = m_xExampleFrame->GetModel();
596  //now the ViewOptions should be set properly
597  Reference< XViewSettingsSupplier > xSettings(xModel->getCurrentController(), UNO_QUERY);
598  m_xViewProperties = xSettings->getViewSettings();
599  auto pXDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(xModel);
600  SwDocShell* pDocShell = pXDoc->GetDocShell();
601  m_pExampleWrtShell = pDocShell->GetWrtShell();
602  OSL_ENSURE(m_pExampleWrtShell, "No SwWrtShell found!");
603  if(!m_pExampleWrtShell)
604  return;
605 
606  SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
607  if(rConfigItem.IsAddressBlock())
608  {
609  m_pAddressBlockFormat = InsertAddressFrame(
610  *m_pExampleWrtShell, rConfigItem,
612  m_xAlignToBodyCB->get_active(), true);
613  }
614  if(rConfigItem.IsGreetingLine(false))
615  {
616  InsertGreeting(*m_pExampleWrtShell, rConfigItem, true);
617  m_bIsGreetingInserted = true;
618  }
619 
620  ZoomHdl_Impl(*m_xZoomLB);
621 
622  const SwFormatFrameSize& rPageSize = m_pExampleWrtShell->GetPageDesc(
623  m_pExampleWrtShell->GetCurPageDesc()).GetMaster().GetFrameSize();
624  m_xLeftMF->set_max(rPageSize.GetWidth() - DEFAULT_LEFT_DISTANCE, FieldUnit::NONE);
625  m_xTopMF->set_max(rPageSize.GetHeight() - DEFAULT_TOP_DISTANCE, FieldUnit::NONE);
626 }
627 
628 IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, weld::ComboBox&, rBox, void)
629 {
630  if (m_pExampleWrtShell)
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 }
650 
652 {
653  if(m_pExampleWrtShell && m_pAddressBlockFormat)
654  {
655  long nLeft = static_cast< long >(m_xLeftMF->denormalize(m_xLeftMF->get_value(FieldUnit::TWIP)));
656  long nTop = static_cast< long >(m_xTopMF->denormalize(m_xTopMF->get_value(FieldUnit::TWIP)));
657 
658  SfxItemSet aSet(
659  m_pExampleWrtShell->GetAttrPool(),
661  if (m_xAlignToBodyCB->get_active())
662  aSet.Put(SwFormatHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA ));
663  else
664  aSet.Put(SwFormatHoriOrient( nLeft, text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
665  aSet.Put(SwFormatVertOrient( nTop, text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ));
666  m_pExampleWrtShell->GetDoc()->SetFlyFrameAttr( *m_pAddressBlockFormat, aSet );
667  m_xExampleFrame->Invalidate();
668  }
669 }
670 
671 IMPL_LINK(SwMailMergeLayoutPage, GreetingsHdl_Impl, weld::Button&, rButton, void)
672 {
673  bool bDown = &rButton == m_xDownPB.get();
674  bool bMoved = m_pExampleWrtShell->MoveParagraph( bDown ? 1 : -1 );
675  if (bMoved || bDown)
676  m_pWizard->GetConfigItem().MoveGreeting(bDown ? 1 : -1 );
677  if(!bMoved && bDown)
678  {
679  //insert a new paragraph before the greeting line
680  m_pExampleWrtShell->SplitNode();
681  }
682  m_xExampleFrame->Invalidate();
683 }
684 
685 IMPL_LINK(SwMailMergeLayoutPage, AlignToTextHdl_Impl, weld::ToggleButton&, rBox, void)
686 {
687  bool bCheck = rBox.get_active() && rBox.get_sensitive();
688  m_xLeftFT->set_sensitive(!bCheck);
689  m_xLeftMF->set_sensitive(!bCheck);
690  ChangeAddressHdl_Impl( *m_xLeftMF );
691 }
692 
693 /* 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
bool AppendTextNode()
Definition: editsh.cxx:204
bool SttPara(bool bSelect=false)
Definition: move.cxx:352
FieldUnit
#define RES_FRM_SIZE
Definition: hintids.hxx:289
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:330
#define UNO_NAME_ZOOM_VALUE
Definition: unoprnms.hxx:419
#define EX_SHOW_DEFAULT_PAGE
Definition: unotools.hxx:34
SwMailMergeConfigItem & GetConfigItem()
#define DEFAULT_ADDRESS_WIDTH
const char aData[]
Definition: ww8scan.hxx:47
bool SttEndDoc(bool bStt)
Definition: crsrsh.cxx:566
fill with spaces and tabs
Definition: crstate.hxx:31
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1002
const LanguageTag & GetUILanguageTag() const
long Height() const
signed char sal_Int8
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:90
#define UNO_NAME_ZOOM_TYPE
Definition: unoprnms.hxx:420
OUString & GetExcludeCountry() const
OUString sDataSource
Definition: swdbdata.hxx:30
static const AllSettings & GetSettings()
#define RES_SURROUND
Definition: hintids.hxx:301
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:233
#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:34
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:291
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
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:202
#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:60
std::unique_ptr< weld::CustomWeld > m_xExampleContainerWIN
bool MovePara(SwWhichPara, SwMoveFnCollection const &)
Definition: crsrsh.cxx:687
bool IsGreetingInserted() const
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:614
IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, weld::ComboBox &, rBox, void)
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
static SW_DLLPUBLIC std::shared_ptr< const SfxFilter > GetFilterOfFormat(const OUString &rFormat, const SfxFilterContainer *pCnt=nullptr)
find for an internal format name the corresponding filter entry
Definition: iodetect.cxx:67
bool SetShadowCursorPos(const Point &rPt, SwFillMode eFillMode)
Definition: crstrvl.cxx:2041
Style of a layout element.
Definition: frmfmt.hxx:57
#define RES_ANCHOR
Definition: hintids.hxx:304
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:686
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:2229
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:222
bool MoveParagraph(long nOffset=1)
Definition: ednumber.cxx:393
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:224
DocumentType const eType
void UnlockExpFields()
Definition: edfld.cxx:356
std::unique_ptr< weld::CheckButton > m_xAlignToBodyCB
#define DB_DELIM
Definition: swtypes.hxx:141
long X() const
SwDocShell * GetDocShell()
Definition: view.cxx:1107
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:182
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:193
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:624
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
#define FILTER_XML
XML filter.
Definition: iodetect.hxx:35
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:520
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
std::unique_ptr< weld::Container > m_xGreetingLine
#define RES_BOX
Definition: hintids.hxx:306
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
virtual void Activate() override
ScXMLEditAttributeMap::Entry const aEntries[]
const SwFrameFormat * GetFlyFrameFormat() const
Get FlyFrameFormat; for UI macro linkage at Flys.
Definition: fefly1.cxx:1228
SwWrtShell * m_pExampleWrtShell
Reference< XModel > xModel
bool IsAddressBlock() const
bool IsEndPara() const
Definition: crsrsh.cxx:1105
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:351
Definition: view.hxx:146
long Y() const
SwFrameFormat * m_pAddressBlockFormat