1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sw.hxx" 30*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION 31*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION 32*cdf0e10cSrcweir #endif 33*cdf0e10cSrcweir #include <swtypes.hxx> 34*cdf0e10cSrcweir #include <mmlayoutpage.hxx> 35*cdf0e10cSrcweir #include <mailmergewizard.hxx> 36*cdf0e10cSrcweir #include <mmconfigitem.hxx> 37*cdf0e10cSrcweir #include <mailmergehelper.hxx> 38*cdf0e10cSrcweir #include <unotools.hxx> 39*cdf0e10cSrcweir #include <unotools/tempfile.hxx> 40*cdf0e10cSrcweir #include <uitool.hxx> 41*cdf0e10cSrcweir #include <svx/dlgutil.hxx> 42*cdf0e10cSrcweir #include <view.hxx> 43*cdf0e10cSrcweir #include <swundo.hxx> 44*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 45*cdf0e10cSrcweir #include <svl/stritem.hxx> 46*cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 47*cdf0e10cSrcweir #include <com/sun/star/text/XParagraphCursor.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/view/XViewSettingsSupplier.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/view/DocumentZoomType.hpp> 50*cdf0e10cSrcweir #include <fldmgr.hxx> 51*cdf0e10cSrcweir #include <fldbas.hxx> 52*cdf0e10cSrcweir #include <poolfmt.hxx> 53*cdf0e10cSrcweir #include <unotxdoc.hxx> 54*cdf0e10cSrcweir #include <docsh.hxx> 55*cdf0e10cSrcweir #include <doc.hxx> 56*cdf0e10cSrcweir #include <wrtsh.hxx> 57*cdf0e10cSrcweir #include <fmtsrnd.hxx> 58*cdf0e10cSrcweir #include <pagedesc.hxx> 59*cdf0e10cSrcweir #include <fmtanchr.hxx> 60*cdf0e10cSrcweir #include <fmtornt.hxx> 61*cdf0e10cSrcweir #include <fmtfsize.hxx> 62*cdf0e10cSrcweir #include <editeng/boxitem.hxx> 63*cdf0e10cSrcweir #include <svl/urihelper.hxx> 64*cdf0e10cSrcweir #include <shellio.hxx> 65*cdf0e10cSrcweir #include <osl/file.hxx> 66*cdf0e10cSrcweir #include <unoprnms.hxx> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include <mmlayoutpage.hrc> 69*cdf0e10cSrcweir #include <dbui.hrc> 70*cdf0e10cSrcweir #include <unomid.h> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir using namespace osl; 73*cdf0e10cSrcweir using namespace svt; 74*cdf0e10cSrcweir using namespace ::com::sun::star; 75*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 76*cdf0e10cSrcweir using namespace ::com::sun::star::text; 77*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 78*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 79*cdf0e10cSrcweir using namespace ::com::sun::star::view; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir #define DEFAULT_LEFT_DISTANCE (MM50*5) // 2,5 cm 82*cdf0e10cSrcweir #define DEFAULT_TOP_DISTANCE (MM50*11) // 5,5 cm 83*cdf0e10cSrcweir #define GREETING_TOP_DISTANCE (MM50*25) //12,5 cm 84*cdf0e10cSrcweir #define DEFAULT_ADDRESS_WIDTH (MM50*15)// 7,5 cm 85*cdf0e10cSrcweir #define DEFAULT_ADDRESS_HEIGHT (MM50*7) // 3,5cm 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /*-- 15.04.2004 08:16:35--------------------------------------------------- 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 90*cdf0e10cSrcweir SwMailMergeLayoutPage::SwMailMergeLayoutPage( SwMailMergeWizard* _pParent) : 91*cdf0e10cSrcweir svt::OWizardPage( _pParent, SW_RES(DLG_MM_LAYOUT_PAGE)), 92*cdf0e10cSrcweir #ifdef MSC 93*cdf0e10cSrcweir #pragma warning (disable : 4355) 94*cdf0e10cSrcweir #endif 95*cdf0e10cSrcweir m_aHeaderFI( this, SW_RES( FI_HEADER )), 96*cdf0e10cSrcweir m_aPositionFL( this, SW_RES( FL_POSITION )), 97*cdf0e10cSrcweir m_aAlignToBodyCB( this, SW_RES( CB_ALIGN )), 98*cdf0e10cSrcweir m_aLeftFT( this, SW_RES( FT_LEFT )), 99*cdf0e10cSrcweir m_aLeftMF( this, SW_RES( MF_LEFT )), 100*cdf0e10cSrcweir m_aTopFT( this, SW_RES( FT_TOP )), 101*cdf0e10cSrcweir m_aTopMF( this, SW_RES( MF_TOP )), 102*cdf0e10cSrcweir m_aGreetingLineFL( this, SW_RES( FL_GREETINGLINE )), 103*cdf0e10cSrcweir m_aUpFT( this, SW_RES( FT_UP )), 104*cdf0e10cSrcweir m_aUpPB( this, SW_RES( MF_UP )), 105*cdf0e10cSrcweir m_aDownFT( this, SW_RES( FT_DOWN )), 106*cdf0e10cSrcweir m_aDownPB( this, SW_RES( PB_DOWN )), 107*cdf0e10cSrcweir m_aExampleContainerWIN( this, SW_RES( WIN_EXAMPLECONTAINER )), 108*cdf0e10cSrcweir m_aExampleWIN( this, 0 ), 109*cdf0e10cSrcweir m_aZoomFT( this, SW_RES( FT_ZOOM )), 110*cdf0e10cSrcweir m_aZoomLB( this, SW_RES( LB_ZOOM )), 111*cdf0e10cSrcweir #ifdef MSC 112*cdf0e10cSrcweir #pragma warning (default : 4355) 113*cdf0e10cSrcweir #endif 114*cdf0e10cSrcweir m_pExampleFrame(0), 115*cdf0e10cSrcweir m_pExampleWrtShell(0), 116*cdf0e10cSrcweir m_pAddressBlockFormat(0), 117*cdf0e10cSrcweir m_bIsGreetingInserted(false), 118*cdf0e10cSrcweir m_pWizard(_pParent) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir FreeResource(); 121*cdf0e10cSrcweir m_aExampleWIN.SetPosSizePixel(m_aExampleContainerWIN.GetPosPixel(), 122*cdf0e10cSrcweir m_aExampleContainerWIN.GetSizePixel()); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat( 126*cdf0e10cSrcweir String::CreateFromAscii( FILTER_XML ), 127*cdf0e10cSrcweir SwDocShell::Factory().GetFilterContainer() ); 128*cdf0e10cSrcweir //save the current document into a temporary file 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir //temp file needs it's own block 131*cdf0e10cSrcweir //creating with extension is not supported by a static method :-( 132*cdf0e10cSrcweir String sLeading; 133*cdf0e10cSrcweir String sExt(pSfxFlt->GetDefaultExtension()); 134*cdf0e10cSrcweir sExt.EraseLeadingChars('*'); 135*cdf0e10cSrcweir utl::TempFile aTempFile( sLeading, &sExt ); 136*cdf0e10cSrcweir m_sExampleURL = aTempFile.GetURL(); 137*cdf0e10cSrcweir aTempFile.EnableKillingFile(); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir SwView* pView = m_pWizard->GetSwView(); 140*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aValues(1); 141*cdf0e10cSrcweir beans::PropertyValue* pValues = aValues.getArray(); 142*cdf0e10cSrcweir pValues[0].Name = C2U("FilterName"); 143*cdf0e10cSrcweir pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName()); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir uno::Reference< frame::XStorable > xStore( pView->GetDocShell()->GetModel(), uno::UNO_QUERY); 146*cdf0e10cSrcweir xStore->storeToURL( m_sExampleURL, aValues ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir Link aLink(LINK(this, SwMailMergeLayoutPage, PreviewLoadedHdl_Impl)); 149*cdf0e10cSrcweir m_pExampleFrame = new SwOneExampleFrame( m_aExampleWIN, 150*cdf0e10cSrcweir EX_SHOW_DEFAULT_PAGE, &aLink, &m_sExampleURL ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir m_aExampleWIN.Show( sal_False ); 153*cdf0e10cSrcweir m_aExampleContainerWIN.Show(sal_True); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir m_aLeftMF.SetValue(m_aLeftMF.Normalize(DEFAULT_LEFT_DISTANCE), FUNIT_TWIP); 156*cdf0e10cSrcweir m_aTopMF.SetValue(m_aTopMF.Normalize(DEFAULT_TOP_DISTANCE), FUNIT_TWIP); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir m_aZoomLB.InsertEntry(String::CreateFromAscii("50 %"), 1); 159*cdf0e10cSrcweir m_aZoomLB.InsertEntry(String::CreateFromAscii("75 %"), 2); 160*cdf0e10cSrcweir m_aZoomLB.InsertEntry(String::CreateFromAscii("100 %"), 3); 161*cdf0e10cSrcweir m_aZoomLB.SelectEntryPos(0); //page size 162*cdf0e10cSrcweir m_aZoomLB.SetSelectHdl(LINK(this, SwMailMergeLayoutPage, ZoomHdl_Impl)); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir Link aFrameHdl = LINK(this, SwMailMergeLayoutPage, ChangeAddressHdl_Impl); 165*cdf0e10cSrcweir m_aLeftMF.SetUpHdl(aFrameHdl); 166*cdf0e10cSrcweir m_aLeftMF.SetDownHdl(aFrameHdl); 167*cdf0e10cSrcweir m_aLeftMF.SetLoseFocusHdl(aFrameHdl); 168*cdf0e10cSrcweir m_aTopMF.SetUpHdl(aFrameHdl); 169*cdf0e10cSrcweir m_aTopMF.SetDownHdl(aFrameHdl); 170*cdf0e10cSrcweir m_aTopMF.SetLoseFocusHdl(aFrameHdl); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir FieldUnit eFieldUnit = ::GetDfltMetric(sal_False); 173*cdf0e10cSrcweir ::SetFieldUnit( m_aLeftMF, eFieldUnit ); 174*cdf0e10cSrcweir ::SetFieldUnit( m_aTopMF, eFieldUnit ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir Link aUpDownHdl = LINK(this, SwMailMergeLayoutPage, GreetingsHdl_Impl ); 177*cdf0e10cSrcweir m_aUpPB.SetClickHdl(aUpDownHdl); 178*cdf0e10cSrcweir m_aDownPB.SetClickHdl(aUpDownHdl); 179*cdf0e10cSrcweir m_aAlignToBodyCB.SetClickHdl(LINK(this, SwMailMergeLayoutPage, AlignToTextHdl_Impl)); 180*cdf0e10cSrcweir m_aAlignToBodyCB.Check(); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir /*-- 15.04.2004 08:17:11--------------------------------------------------- 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 185*cdf0e10cSrcweir SwMailMergeLayoutPage::~SwMailMergeLayoutPage() 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir delete m_pExampleFrame; 188*cdf0e10cSrcweir File::remove( m_sExampleURL ); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir /*-- 27.05.2004 13:41:04--------------------------------------------------- 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 194*cdf0e10cSrcweir void SwMailMergeLayoutPage::ActivatePage() 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 197*cdf0e10cSrcweir sal_Bool bGreetingLine = rConfigItem.IsGreetingLine(sal_False) && !rConfigItem.IsGreetingInserted(); 198*cdf0e10cSrcweir sal_Bool bAddressBlock = rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted(); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir m_aPositionFL.Enable(bAddressBlock); 201*cdf0e10cSrcweir m_aLeftFT.Enable(bAddressBlock); 202*cdf0e10cSrcweir m_aTopFT.Enable(bAddressBlock); 203*cdf0e10cSrcweir m_aLeftMF.Enable(bAddressBlock); 204*cdf0e10cSrcweir m_aTopMF.Enable(bAddressBlock); 205*cdf0e10cSrcweir AlignToTextHdl_Impl( &m_aAlignToBodyCB ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir m_aGreetingLineFL.Enable(bGreetingLine); 208*cdf0e10cSrcweir m_aUpPB.Enable(bGreetingLine); 209*cdf0e10cSrcweir m_aDownPB.Enable(bGreetingLine); 210*cdf0e10cSrcweir m_aUpFT.Enable(bGreetingLine); 211*cdf0e10cSrcweir m_aDownFT.Enable(bGreetingLine); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //check if greeting and/or address frame have to be inserted/removed 214*cdf0e10cSrcweir if(m_pExampleWrtShell) // initially there's nothing to check 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir if(!rConfigItem.IsGreetingInserted() && 217*cdf0e10cSrcweir m_bIsGreetingInserted != (0 != bGreetingLine) ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if( m_bIsGreetingInserted ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir m_pExampleWrtShell->DelFullPara(); 222*cdf0e10cSrcweir m_bIsGreetingInserted = false; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir else 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir InsertGreeting(*m_pExampleWrtShell, m_pWizard->GetConfigItem(), true); 227*cdf0e10cSrcweir m_bIsGreetingInserted = true; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir if(!rConfigItem.IsAddressInserted() && 231*cdf0e10cSrcweir rConfigItem.IsAddressBlock() != ( 0 != m_pAddressBlockFormat )) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir if( m_pAddressBlockFormat ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir m_pExampleWrtShell->Push(); 236*cdf0e10cSrcweir m_pExampleWrtShell->GotoFly( m_pAddressBlockFormat->GetName() ); 237*cdf0e10cSrcweir m_pExampleWrtShell->DelRight(); 238*cdf0e10cSrcweir m_pAddressBlockFormat = 0; 239*cdf0e10cSrcweir m_pExampleWrtShell->Pop(sal_False); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir else 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir long nLeft = static_cast< long >(m_aLeftMF.Denormalize(m_aLeftMF.GetValue(FUNIT_TWIP))); 244*cdf0e10cSrcweir long nTop = static_cast< long >(m_aTopMF.Denormalize(m_aTopMF.GetValue(FUNIT_TWIP))); 245*cdf0e10cSrcweir m_pAddressBlockFormat = InsertAddressFrame( 246*cdf0e10cSrcweir *m_pExampleWrtShell, m_pWizard->GetConfigItem(), 247*cdf0e10cSrcweir Point(nLeft, nTop), 248*cdf0e10cSrcweir m_aAlignToBodyCB.IsChecked(), true); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir /*-- 11.05.2004 10:41:26--------------------------------------------------- 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 257*cdf0e10cSrcweir sal_Bool SwMailMergeLayoutPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir //now insert the frame and the greeting 260*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 261*cdf0e10cSrcweir if(::svt::WizardTypes::eTravelForward == _eReason) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir long nLeft = static_cast< long >(m_aLeftMF.Denormalize(m_aLeftMF.GetValue(FUNIT_TWIP))); 264*cdf0e10cSrcweir long nTop = static_cast< long >(m_aTopMF.Denormalize(m_aTopMF.GetValue(FUNIT_TWIP))); 265*cdf0e10cSrcweir InsertAddressAndGreeting( 266*cdf0e10cSrcweir m_pWizard->GetSwView(), 267*cdf0e10cSrcweir rConfigItem, 268*cdf0e10cSrcweir Point(nLeft, nTop), 269*cdf0e10cSrcweir m_aAlignToBodyCB.IsChecked()); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir return sal_True; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir /*-- 24.06.2004 09:50:26--------------------------------------------------- 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 276*cdf0e10cSrcweir SwFrmFmt* SwMailMergeLayoutPage::InsertAddressAndGreeting(SwView* pView, 277*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem, 278*cdf0e10cSrcweir const Point& rAddressPosition, 279*cdf0e10cSrcweir bool bAlignToBody) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir SwFrmFmt* pAddressBlockFormat = 0; 282*cdf0e10cSrcweir pView->GetWrtShell().StartUndo(UNDO_INSERT); 283*cdf0e10cSrcweir if(rConfigItem.IsAddressBlock() && !rConfigItem.IsAddressInserted()) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir //insert the frame 286*cdf0e10cSrcweir Point aAddressPosition(DEFAULT_LEFT_DISTANCE, DEFAULT_TOP_DISTANCE); 287*cdf0e10cSrcweir if(rAddressPosition.X() > 0 && rAddressPosition.Y() > 0) 288*cdf0e10cSrcweir aAddressPosition = rAddressPosition; 289*cdf0e10cSrcweir pAddressBlockFormat = InsertAddressFrame( pView->GetWrtShell(), 290*cdf0e10cSrcweir rConfigItem, 291*cdf0e10cSrcweir aAddressPosition, bAlignToBody, false); 292*cdf0e10cSrcweir rConfigItem.SetAddressInserted(pAddressBlockFormat->GetName()); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir //now the greeting 295*cdf0e10cSrcweir if(rConfigItem.IsGreetingLine(sal_False) && !rConfigItem.IsGreetingInserted()) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir InsertGreeting( pView->GetWrtShell(), rConfigItem, false); 298*cdf0e10cSrcweir rConfigItem.SetGreetingInserted(); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir pView->GetWrtShell().EndUndo(UNDO_INSERT); 301*cdf0e10cSrcweir return pAddressBlockFormat; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir /*-- 11.05.2004 12:49:04--------------------------------------------------- 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 306*cdf0e10cSrcweir SwFrmFmt* SwMailMergeLayoutPage::InsertAddressFrame( 307*cdf0e10cSrcweir SwWrtShell& rShell, 308*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem, 309*cdf0e10cSrcweir const Point& rDestination, 310*cdf0e10cSrcweir bool bAlignLeft, 311*cdf0e10cSrcweir bool bExample) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir // insert the address block and the greeting line 314*cdf0e10cSrcweir SfxItemSet aSet(rShell.GetAttrPool(), RES_ANCHOR, RES_ANCHOR, 315*cdf0e10cSrcweir RES_VERT_ORIENT, RES_VERT_ORIENT, 316*cdf0e10cSrcweir RES_HORI_ORIENT, RES_HORI_ORIENT, 317*cdf0e10cSrcweir RES_BOX, RES_BOX, 318*cdf0e10cSrcweir RES_FRM_SIZE, RES_FRM_SIZE, 319*cdf0e10cSrcweir RES_SURROUND, RES_SURROUND, 320*cdf0e10cSrcweir 0 ); 321*cdf0e10cSrcweir aSet.Put(SwFmtAnchor(FLY_AT_PAGE, 1)); 322*cdf0e10cSrcweir if(bAlignLeft) 323*cdf0e10cSrcweir aSet.Put(SwFmtHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA )); 324*cdf0e10cSrcweir else 325*cdf0e10cSrcweir aSet.Put(SwFmtHoriOrient( rDestination.X(), text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME )); 326*cdf0e10cSrcweir aSet.Put(SwFmtVertOrient( rDestination.Y(), text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME )); 327*cdf0e10cSrcweir aSet.Put(SwFmtFrmSize( ATT_MIN_SIZE, DEFAULT_ADDRESS_WIDTH, DEFAULT_ADDRESS_HEIGHT )); 328*cdf0e10cSrcweir // the example gets a border around the frame, the real document doesn't get one 329*cdf0e10cSrcweir if(!bExample) 330*cdf0e10cSrcweir aSet.Put(SvxBoxItem( RES_BOX )); 331*cdf0e10cSrcweir aSet.Put(SwFmtSurround( SURROUND_NONE )); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir rShell.NewFlyFrm(aSet, sal_True ); 334*cdf0e10cSrcweir SwFrmFmt* pRet = rShell.GetFlyFrmFmt(); 335*cdf0e10cSrcweir ASSERT( pRet, "Fly not inserted" ); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir rShell.UnSelectFrm(); 338*cdf0e10cSrcweir const Sequence< ::rtl::OUString> aBlocks = rConfigItem.GetAddressBlocks(); 339*cdf0e10cSrcweir if(bExample) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir rShell.Insert(aBlocks[0]); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir else 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir //the placeholders should be replaced by the appropriate fields 346*cdf0e10cSrcweir SwFldMgr aFldMgr(&rShell); 347*cdf0e10cSrcweir //create a database string source.command.commandtype.column 348*cdf0e10cSrcweir const SwDBData& rData = rConfigItem.GetCurrentDBData(); 349*cdf0e10cSrcweir String sDBName(rData.sDataSource); 350*cdf0e10cSrcweir sDBName += DB_DELIM; 351*cdf0e10cSrcweir sDBName += String(rData.sCommand); 352*cdf0e10cSrcweir sDBName += DB_DELIM; 353*cdf0e10cSrcweir String sDatabaseConditionPrefix(sDBName); 354*cdf0e10cSrcweir sDatabaseConditionPrefix.SearchAndReplaceAll(DB_DELIM, '.'); 355*cdf0e10cSrcweir sDBName += String::CreateFromInt32(rData.nCommandType); 356*cdf0e10cSrcweir sDBName += DB_DELIM; 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir // if only the country is in an address line the 359*cdf0e10cSrcweir // paragraph has to be hidden depending on the 360*cdf0e10cSrcweir // IsIncludeCountry()/GetExcludeCountry() settings 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry(); 363*cdf0e10cSrcweir sal_Bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs(); 364*cdf0e10cSrcweir const ::rtl::OUString rExcludeCountry = rConfigItem.GetExcludeCountry(); 365*cdf0e10cSrcweir bool bSpecialReplacementForCountry = (!bIncludeCountry || rExcludeCountry.getLength()); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders(); 368*cdf0e10cSrcweir String sCountryColumn = rHeaders.GetString(MM_PART_COUNTRY); 369*cdf0e10cSrcweir Sequence< ::rtl::OUString> aAssignment = 370*cdf0e10cSrcweir rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() ); 371*cdf0e10cSrcweir const ::rtl::OUString* pAssignment = aAssignment.getConstArray(); 372*cdf0e10cSrcweir if(aAssignment.getLength() > MM_PART_COUNTRY && aAssignment[MM_PART_COUNTRY].getLength()) 373*cdf0e10cSrcweir sCountryColumn = aAssignment[MM_PART_COUNTRY]; 374*cdf0e10cSrcweir // 375*cdf0e10cSrcweir String sHideParagraphsExpression; 376*cdf0e10cSrcweir SwAddressIterator aIter(aBlocks[0]); 377*cdf0e10cSrcweir while(aIter.HasMore()) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir SwMergeAddressItem aItem = aIter.Next(); 380*cdf0e10cSrcweir if(aItem.bIsColumn) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir String sConvertedColumn = aItem.sText; 383*cdf0e10cSrcweir for(sal_uInt16 nColumn = 0; 384*cdf0e10cSrcweir nColumn < rHeaders.Count() && nColumn < aAssignment.getLength(); 385*cdf0e10cSrcweir ++nColumn) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir if(rHeaders.GetString(nColumn) == aItem.sText && 388*cdf0e10cSrcweir pAssignment[nColumn].getLength()) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir sConvertedColumn = pAssignment[nColumn]; 391*cdf0e10cSrcweir break; 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir String sDB(sDBName); 395*cdf0e10cSrcweir sDB += sConvertedColumn; 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir if(sHideParagraphsExpression.Len()) 398*cdf0e10cSrcweir sHideParagraphsExpression.AppendAscii(" AND "); 399*cdf0e10cSrcweir sHideParagraphsExpression += '!'; 400*cdf0e10cSrcweir sHideParagraphsExpression += '['; 401*cdf0e10cSrcweir sHideParagraphsExpression += sDatabaseConditionPrefix; 402*cdf0e10cSrcweir sHideParagraphsExpression += sConvertedColumn; 403*cdf0e10cSrcweir sHideParagraphsExpression += ']'; 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir // now insert a hidden paragraph field 408*cdf0e10cSrcweir String sExpression; 409*cdf0e10cSrcweir if( rExcludeCountry.getLength() ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir sExpression = sDatabaseConditionPrefix; 412*cdf0e10cSrcweir sExpression.Insert('[', 0); 413*cdf0e10cSrcweir sExpression += sCountryColumn; 414*cdf0e10cSrcweir sExpression.AppendAscii("]"); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir String sCondition(sExpression); 417*cdf0e10cSrcweir sCondition.AppendAscii(" != \""); 418*cdf0e10cSrcweir sCondition += String(rExcludeCountry); 419*cdf0e10cSrcweir sCondition += '\"'; 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_CONDTXTFLD, 0, sCondition, sExpression, 0, &rShell ); 422*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir else 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_HIDDENPARAFLD, 0, sExpression, aEmptyStr, 0, &rShell ); 427*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir else 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_DBFLD, 0, sDB, aEmptyStr, 0, &rShell ); 433*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir else if(!aItem.bIsReturn) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir rShell.Insert(aItem.sText); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir else 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir if(bHideEmptyParagraphs) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_HIDDENPARAFLD, 0, sHideParagraphsExpression, aEmptyStr, 0, &rShell ); 445*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir sHideParagraphsExpression.Erase(); 448*cdf0e10cSrcweir //now add a new paragraph 449*cdf0e10cSrcweir rShell.SplitNode(); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir if(bHideEmptyParagraphs && sHideParagraphsExpression.Len()) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_HIDDENPARAFLD, 0, sHideParagraphsExpression, aEmptyStr, 0, &rShell ); 455*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir return pRet; 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir /*-- 12.05.2004 12:20:19--------------------------------------------------- 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 464*cdf0e10cSrcweir void SwMailMergeLayoutPage::InsertGreeting(SwWrtShell& rShell, SwMailMergeConfigItem& rConfigItem, bool bExample) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir //set the cursor to the desired position - if no text content is here then 467*cdf0e10cSrcweir //new paragraphs are inserted 468*cdf0e10cSrcweir const SwRect& rPageRect = rShell.GetAnyCurRect(RECT_PAGE); 469*cdf0e10cSrcweir const Point aGreetingPos( DEFAULT_LEFT_DISTANCE + rPageRect.Left(), GREETING_TOP_DISTANCE ); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir const sal_Bool bRet = rShell.SetShadowCrsrPos( aGreetingPos, FILL_SPACE ); 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir if(!bRet) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir //there's already text at the desired position 476*cdf0e10cSrcweir //go to start of the doc, directly! 477*cdf0e10cSrcweir rShell.SttEndDoc(sal_True); 478*cdf0e10cSrcweir //and go by paragraph until the position is reached 479*cdf0e10cSrcweir long nYPos = rShell.GetCharRect().Top(); 480*cdf0e10cSrcweir while(nYPos < GREETING_TOP_DISTANCE) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir if(!rShell.FwdPara()) 483*cdf0e10cSrcweir break; 484*cdf0e10cSrcweir nYPos = rShell.GetCharRect().Top(); 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir //text needs to be appended 487*cdf0e10cSrcweir while(nYPos < GREETING_TOP_DISTANCE) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir if(!rShell.AppendTxtNode()) 490*cdf0e10cSrcweir break; 491*cdf0e10cSrcweir nYPos = rShell.GetCharRect().Top(); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir else 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir //we may end up inside of a paragraph if the left margin is not at DEFAULT_LEFT_DISTANCE 497*cdf0e10cSrcweir rShell.MovePara(GetfnParaCurr(), GetfnParaStart()); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir bool bSplitNode = rShell.GetText().Len() > 0; 500*cdf0e10cSrcweir // rShell.SetTxtFmtColl( rShell.GetTxtCollFromPool( RES_POOLCOLL_GREETING ) ); 501*cdf0e10cSrcweir sal_Int32 nMoves = rConfigItem.GetGreetingMoves(); 502*cdf0e10cSrcweir if( !bExample && 0 != nMoves ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir if(nMoves < 0) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir rShell.MoveParagraph( nMoves ); 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir else 509*cdf0e10cSrcweir while(nMoves) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir sal_Bool bMoved = rShell.MoveParagraph( 1 ); 512*cdf0e10cSrcweir if(!bMoved) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir //insert a new paragraph before the greeting line 515*cdf0e10cSrcweir rShell.SplitNode(); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir --nMoves; 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir //now insert the greeting text - if we have any? 521*cdf0e10cSrcweir const sal_Bool bIndividual = rConfigItem.IsIndividualGreeting(sal_False); 522*cdf0e10cSrcweir String sGreeting; 523*cdf0e10cSrcweir if(bIndividual) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir //lock expression fields - prevents hiding of the paragraph to insert into 526*cdf0e10cSrcweir rShell.LockExpFlds(); 527*cdf0e10cSrcweir if(bExample) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir for(sal_Int8 eGender = SwMailMergeConfigItem::FEMALE; 530*cdf0e10cSrcweir eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir Sequence< ::rtl::OUString > aEntries = 533*cdf0e10cSrcweir rConfigItem.GetGreetings((SwMailMergeConfigItem::Gender)eGender); 534*cdf0e10cSrcweir sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting((SwMailMergeConfigItem::Gender)eGender); 535*cdf0e10cSrcweir if( nCurrent >= 0 && nCurrent < aEntries.getLength()) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir sGreeting = aEntries[nCurrent]; 538*cdf0e10cSrcweir rShell.Insert(sGreeting); 539*cdf0e10cSrcweir break; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir else 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir SwFldMgr aFldMgr(&rShell); 546*cdf0e10cSrcweir //three paragraphs, each with an appropriate hidden paragraph field 547*cdf0e10cSrcweir //are to be inserted 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir //name of the gender column 550*cdf0e10cSrcweir String sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER); 551*cdf0e10cSrcweir String sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME); 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir const ::rtl::OUString& rFemaleGenderValue = rConfigItem.GetFemaleGenderValue(); 554*cdf0e10cSrcweir sal_Bool bHideEmptyParagraphs = rConfigItem.IsHideEmptyParagraphs(); 555*cdf0e10cSrcweir const SwDBData& rData = rConfigItem.GetCurrentDBData(); 556*cdf0e10cSrcweir String sConditionBase(rData.sDataSource); 557*cdf0e10cSrcweir sConditionBase += '.'; 558*cdf0e10cSrcweir sConditionBase += String(rData.sCommand); 559*cdf0e10cSrcweir sConditionBase += '.'; 560*cdf0e10cSrcweir //split the name column from here 561*cdf0e10cSrcweir String sNameColumnBase(sConditionBase); 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir sConditionBase += String(sGenderColumn); 564*cdf0e10cSrcweir sConditionBase += ']'; 565*cdf0e10cSrcweir sConditionBase.Insert('[', 0); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir sNameColumnBase += String(sNameColumn); 568*cdf0e10cSrcweir sNameColumnBase += ']'; 569*cdf0e10cSrcweir sNameColumnBase.Insert('[', 0); 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir String sDBName(rData.sDataSource); 572*cdf0e10cSrcweir sDBName += DB_DELIM; 573*cdf0e10cSrcweir sDBName += String(rData.sCommand); 574*cdf0e10cSrcweir sDBName += DB_DELIM; 575*cdf0e10cSrcweir sDBName += String::CreateFromInt32(rData.nCommandType); 576*cdf0e10cSrcweir sDBName += DB_DELIM; 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir // Female: [database.sGenderColumn] != "rFemaleGenderValue" && [database.NameColumn] 579*cdf0e10cSrcweir // Male: [database.sGenderColumn] == "rFemaleGenderValue" && [database.rGenderColumn] 580*cdf0e10cSrcweir // Neutral: [database.sNameColumn] 581*cdf0e10cSrcweir DBG_ASSERT(sGenderColumn.Len() && rFemaleGenderValue.getLength(), 582*cdf0e10cSrcweir "gender settings not available - how to form the condition?"); 583*cdf0e10cSrcweir //column used as lastname 584*cdf0e10cSrcweir for(sal_Int8 eGender = SwMailMergeConfigItem::FEMALE; 585*cdf0e10cSrcweir eGender <= SwMailMergeConfigItem::NEUTRAL; ++eGender) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir Sequence< ::rtl::OUString> aEntries = rConfigItem.GetGreetings((SwMailMergeConfigItem::Gender)eGender); 588*cdf0e10cSrcweir sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting((SwMailMergeConfigItem::Gender)eGender); 589*cdf0e10cSrcweir if( nCurrent >= 0 && nCurrent < aEntries.getLength()) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir sGreeting = aEntries[nCurrent]; 592*cdf0e10cSrcweir String sCondition(sConditionBase); 593*cdf0e10cSrcweir String sHideParagraphsExpression; 594*cdf0e10cSrcweir switch(eGender) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir case SwMailMergeConfigItem::FEMALE: 597*cdf0e10cSrcweir sCondition.AppendAscii(" != \""); 598*cdf0e10cSrcweir sCondition += String(rFemaleGenderValue); 599*cdf0e10cSrcweir sCondition.AppendAscii("\" OR NOT "); 600*cdf0e10cSrcweir sCondition += String(sNameColumnBase); 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir sHideParagraphsExpression += '!'; 603*cdf0e10cSrcweir sHideParagraphsExpression += sNameColumnBase; 604*cdf0e10cSrcweir break; 605*cdf0e10cSrcweir case SwMailMergeConfigItem::MALE: 606*cdf0e10cSrcweir sCondition.AppendAscii(" == \""); 607*cdf0e10cSrcweir sCondition += String(rFemaleGenderValue); 608*cdf0e10cSrcweir sCondition.AppendAscii("\" OR NOT "); 609*cdf0e10cSrcweir sCondition += String(sNameColumnBase); 610*cdf0e10cSrcweir break; 611*cdf0e10cSrcweir case SwMailMergeConfigItem::NEUTRAL: 612*cdf0e10cSrcweir sCondition = sNameColumnBase; 613*cdf0e10cSrcweir break; 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir if(bHideEmptyParagraphs && sHideParagraphsExpression.Len()) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir String sComplete( sCondition ); 619*cdf0e10cSrcweir sComplete.Insert('(', 0); 620*cdf0e10cSrcweir sComplete.AppendAscii( ") OR ("); 621*cdf0e10cSrcweir sComplete += sHideParagraphsExpression; 622*cdf0e10cSrcweir sComplete += ')'; 623*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_HIDDENPARAFLD, 0, sComplete, aEmptyStr, 0, &rShell ); 624*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir else 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_HIDDENPARAFLD, 0, sCondition, aEmptyStr, 0, &rShell ); 629*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir //now the text has to be inserted 632*cdf0e10cSrcweir const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders(); 633*cdf0e10cSrcweir Sequence< ::rtl::OUString> aAssignment = 634*cdf0e10cSrcweir rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() ); 635*cdf0e10cSrcweir const ::rtl::OUString* pAssignment = aAssignment.getConstArray(); 636*cdf0e10cSrcweir SwAddressIterator aIter(sGreeting); 637*cdf0e10cSrcweir while(aIter.HasMore()) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir SwMergeAddressItem aItem = aIter.Next(); 640*cdf0e10cSrcweir if(aItem.bIsColumn) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir String sDB(sDBName); 643*cdf0e10cSrcweir String sConvertedColumn = aItem.sText; 644*cdf0e10cSrcweir for(sal_uInt16 nColumn = 0; 645*cdf0e10cSrcweir nColumn < rHeaders.Count() && nColumn < aAssignment.getLength(); 646*cdf0e10cSrcweir ++nColumn) 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir if(rHeaders.GetString(nColumn) == aItem.sText && 649*cdf0e10cSrcweir pAssignment[nColumn].getLength()) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir sConvertedColumn = pAssignment[nColumn]; 652*cdf0e10cSrcweir break; 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir sDB += sConvertedColumn; 656*cdf0e10cSrcweir SwInsertFld_Data aData(TYP_DBFLD, 0, sDB, aEmptyStr, 0, &rShell ); 657*cdf0e10cSrcweir aFldMgr.InsertFld( aData ); 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir else 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir rShell.Insert(aItem.sText); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir //now add a new paragraph 665*cdf0e10cSrcweir rShell.SplitNode(); 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir rShell.UnlockExpFlds(); 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir else 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir Sequence< ::rtl::OUString> aEntries = rConfigItem.GetGreetings(SwMailMergeConfigItem::NEUTRAL); 675*cdf0e10cSrcweir sal_Int32 nCurrent = rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL); 676*cdf0e10cSrcweir if( nCurrent >= 0 && nCurrent < aEntries.getLength()) 677*cdf0e10cSrcweir sGreeting = aEntries[nCurrent]; 678*cdf0e10cSrcweir rShell.Insert(sGreeting); 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir // now insert a new paragraph here if necessary 681*cdf0e10cSrcweir if(bSplitNode) 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir rShell.Push(); 684*cdf0e10cSrcweir rShell.SplitNode(); 685*cdf0e10cSrcweir rShell.Pop(sal_False); 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir //put the cursor to the start of the paragraph 688*cdf0e10cSrcweir rShell.SttPara(); 689*cdf0e10cSrcweir 690*cdf0e10cSrcweir DBG_ASSERT(0 == rShell.GetTableFmt(), "What to do with a table here?"); 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir /*-- 10.05.2004 09:34:25--------------------------------------------------- 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 695*cdf0e10cSrcweir IMPL_LINK(SwMailMergeLayoutPage, PreviewLoadedHdl_Impl, void*, EMPTYARG) 696*cdf0e10cSrcweir { 697*cdf0e10cSrcweir m_aExampleWIN.Show( sal_True ); 698*cdf0e10cSrcweir m_aExampleContainerWIN.Show(sal_False); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir Reference< XModel > & xModel = m_pExampleFrame->GetModel(); 701*cdf0e10cSrcweir //now the ViewOptions should be set properly 702*cdf0e10cSrcweir Reference< XViewSettingsSupplier > xSettings(xModel->getCurrentController(), UNO_QUERY); 703*cdf0e10cSrcweir m_xViewProperties = xSettings->getViewSettings(); 704*cdf0e10cSrcweir Reference< XUnoTunnel > xDocTunnel(xModel, UNO_QUERY); 705*cdf0e10cSrcweir SwXTextDocument* pXDoc = reinterpret_cast<SwXTextDocument*>(xDocTunnel->getSomething(SwXTextDocument::getUnoTunnelId())); 706*cdf0e10cSrcweir SwDocShell* pDocShell = pXDoc->GetDocShell(); 707*cdf0e10cSrcweir m_pExampleWrtShell = pDocShell->GetWrtShell(); 708*cdf0e10cSrcweir DBG_ASSERT(m_pExampleWrtShell, "No SwWrtShell found!"); 709*cdf0e10cSrcweir if(!m_pExampleWrtShell) 710*cdf0e10cSrcweir return 0; 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 713*cdf0e10cSrcweir if(rConfigItem.IsAddressBlock()) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir m_pAddressBlockFormat = InsertAddressFrame( 716*cdf0e10cSrcweir *m_pExampleWrtShell, rConfigItem, 717*cdf0e10cSrcweir Point(DEFAULT_LEFT_DISTANCE, DEFAULT_TOP_DISTANCE), 718*cdf0e10cSrcweir m_aAlignToBodyCB.IsChecked(), true); 719*cdf0e10cSrcweir } 720*cdf0e10cSrcweir if(rConfigItem.IsGreetingLine(sal_False)) 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir InsertGreeting(*m_pExampleWrtShell, rConfigItem, true); 723*cdf0e10cSrcweir m_bIsGreetingInserted = true; 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir Any aZoom; 727*cdf0e10cSrcweir aZoom <<= (sal_Int16)DocumentZoomType::ENTIRE_PAGE; 728*cdf0e10cSrcweir m_xViewProperties->setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_ZOOM_TYPE)), aZoom); 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir // m_pExampleWrtShell->SetTxtFmtColl( rSh.GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) ); 732*cdf0e10cSrcweir const SwFmtFrmSize& rPageSize = m_pExampleWrtShell->GetPageDesc( 733*cdf0e10cSrcweir m_pExampleWrtShell->GetCurPageDesc()).GetMaster().GetFrmSize(); 734*cdf0e10cSrcweir m_aLeftMF.SetMax(rPageSize.GetWidth() - DEFAULT_LEFT_DISTANCE); 735*cdf0e10cSrcweir m_aTopMF.SetMax(rPageSize.GetHeight() - DEFAULT_TOP_DISTANCE); 736*cdf0e10cSrcweir return 0; 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir /*-- 10.05.2004 14:05:24--------------------------------------------------- 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 741*cdf0e10cSrcweir IMPL_LINK(SwMailMergeLayoutPage, ZoomHdl_Impl, ListBox*, pBox) 742*cdf0e10cSrcweir { 743*cdf0e10cSrcweir if(m_pExampleWrtShell) 744*cdf0e10cSrcweir { 745*cdf0e10cSrcweir sal_Int16 eType = DocumentZoomType::BY_VALUE; 746*cdf0e10cSrcweir short nZoom = 50; 747*cdf0e10cSrcweir switch(pBox->GetSelectEntryPos()) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir case 0 : eType = DocumentZoomType::ENTIRE_PAGE; break; 750*cdf0e10cSrcweir case 1 : nZoom = 50; break; 751*cdf0e10cSrcweir case 2 : nZoom = 75; break; 752*cdf0e10cSrcweir case 3 : nZoom = 100; break; 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir Any aZoom; 755*cdf0e10cSrcweir aZoom <<= eType; 756*cdf0e10cSrcweir m_xViewProperties->setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_ZOOM_TYPE)), aZoom); 757*cdf0e10cSrcweir aZoom <<= nZoom; 758*cdf0e10cSrcweir m_xViewProperties->setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_ZOOM_VALUE)), aZoom); 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir return 0; 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir /*-- 10.05.2004 15:56:51--------------------------------------------------- 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 768*cdf0e10cSrcweir IMPL_LINK(SwMailMergeLayoutPage, ChangeAddressHdl_Impl, MetricField*, EMPTYARG) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir if(m_pExampleWrtShell && m_pAddressBlockFormat) 771*cdf0e10cSrcweir { 772*cdf0e10cSrcweir long nLeft = static_cast< long >(m_aLeftMF.Denormalize(m_aLeftMF.GetValue(FUNIT_TWIP))); 773*cdf0e10cSrcweir long nTop = static_cast< long >(m_aTopMF.Denormalize(m_aTopMF.GetValue(FUNIT_TWIP))); 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir SfxItemSet aSet(m_pExampleWrtShell->GetAttrPool(), RES_ANCHOR, RES_ANCHOR, 776*cdf0e10cSrcweir RES_VERT_ORIENT, RES_VERT_ORIENT, 777*cdf0e10cSrcweir RES_HORI_ORIENT, RES_HORI_ORIENT, 778*cdf0e10cSrcweir 0 ); 779*cdf0e10cSrcweir if(m_aAlignToBodyCB.IsChecked()) 780*cdf0e10cSrcweir aSet.Put(SwFmtHoriOrient( 0, text::HoriOrientation::NONE, text::RelOrientation::PAGE_PRINT_AREA )); 781*cdf0e10cSrcweir else 782*cdf0e10cSrcweir aSet.Put(SwFmtHoriOrient( nLeft, text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME )); 783*cdf0e10cSrcweir aSet.Put(SwFmtVertOrient( nTop, text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME )); 784*cdf0e10cSrcweir m_pExampleWrtShell->GetDoc()->SetFlyFrmAttr( *m_pAddressBlockFormat, aSet ); 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir return 0; 787*cdf0e10cSrcweir } 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir /*-- 10.05.2004 16:13:36--------------------------------------------------- 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 792*cdf0e10cSrcweir IMPL_LINK(SwMailMergeLayoutPage, GreetingsHdl_Impl, PushButton*, pButton) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir bool bDown = pButton == &m_aDownPB; 795*cdf0e10cSrcweir sal_Bool bMoved = m_pExampleWrtShell->MoveParagraph( bDown ? 1 : -1 ); 796*cdf0e10cSrcweir if (bMoved || bDown) 797*cdf0e10cSrcweir m_pWizard->GetConfigItem().MoveGreeting(bDown ? 1 : -1 ); 798*cdf0e10cSrcweir if(!bMoved && bDown) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir //insert a new paragraph before the greeting line 801*cdf0e10cSrcweir m_pExampleWrtShell->SplitNode(); 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir return 0; 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir /*-- 15.07.2004 16:05:30--------------------------------------------------- 807*cdf0e10cSrcweir 808*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 809*cdf0e10cSrcweir IMPL_LINK(SwMailMergeLayoutPage, AlignToTextHdl_Impl, CheckBox*, pBox) 810*cdf0e10cSrcweir { 811*cdf0e10cSrcweir sal_Bool bCheck = pBox->IsChecked() && pBox->IsEnabled(); 812*cdf0e10cSrcweir m_aLeftFT.Enable(!bCheck); 813*cdf0e10cSrcweir m_aLeftMF.Enable(!bCheck); 814*cdf0e10cSrcweir ChangeAddressHdl_Impl( 0 ); 815*cdf0e10cSrcweir return 0; 816*cdf0e10cSrcweir } 817