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