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