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 31*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION 32*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #include <mmpreparemergepage.hxx> 35*cdf0e10cSrcweir #include <mailmergewizard.hxx> 36*cdf0e10cSrcweir #include <mmconfigitem.hxx> 37*cdf0e10cSrcweir #ifndef _DBUI_HRC 38*cdf0e10cSrcweir #include <dbui.hrc> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #include <swtypes.hxx> 41*cdf0e10cSrcweir #ifndef _VIEW_HXX 42*cdf0e10cSrcweir #include <view.hxx> 43*cdf0e10cSrcweir #endif 44*cdf0e10cSrcweir #ifndef _DBMGR_HXX 45*cdf0e10cSrcweir #include <dbmgr.hxx> 46*cdf0e10cSrcweir #endif 47*cdf0e10cSrcweir #include <wrtsh.hxx> 48*cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx> 49*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp> 50*cdf0e10cSrcweir #include <swabstdlg.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <mmpreparemergepage.hrc> 54*cdf0e10cSrcweir #include <dbui.hrc> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include <unomid.h> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 59*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 60*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 61*cdf0e10cSrcweir using ::rtl::OUString; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /*-- 02.04.2004 16:42:49--------------------------------------------------- 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 66*cdf0e10cSrcweir SwMailMergePrepareMergePage::SwMailMergePrepareMergePage( SwMailMergeWizard* _pParent) : 67*cdf0e10cSrcweir svt::OWizardPage( _pParent, SW_RES(DLG_MM_PREPAREMERGE_PAGE)), 68*cdf0e10cSrcweir #ifdef MSC 69*cdf0e10cSrcweir #pragma warning (disable : 4355) 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir m_aHeaderFI(this, SW_RES( FI_HEADER ) ), 72*cdf0e10cSrcweir m_aPreviewFI(this, SW_RES( FI_PREVIEW ) ), 73*cdf0e10cSrcweir m_aRecipientFT(this, SW_RES( FT_RECIPIENT ) ), 74*cdf0e10cSrcweir m_aFirstPB(this, SW_RES( PB_FIRST ) ), 75*cdf0e10cSrcweir m_aPrevPB(this, SW_RES( PB_PREV ) ), 76*cdf0e10cSrcweir m_aRecordED(this, SW_RES( ED_RECORD ) ), 77*cdf0e10cSrcweir m_aNextPB(this, SW_RES( PB_NEXT ) ), 78*cdf0e10cSrcweir m_aLastPB(this, SW_RES( PB_LAST ) ), 79*cdf0e10cSrcweir m_ExcludeCB(this, SW_RES( CB_EXCLUDE ) ), 80*cdf0e10cSrcweir m_aNoteHeaderFL(this, SW_RES( FL_NOTEHEADER ) ), 81*cdf0e10cSrcweir m_aEditFI(this, SW_RES( FI_EDIT ) ), 82*cdf0e10cSrcweir m_aEditPB(this, SW_RES( PB_EDIT ) ), 83*cdf0e10cSrcweir #ifdef MSC 84*cdf0e10cSrcweir #pragma warning (default : 4355) 85*cdf0e10cSrcweir #endif 86*cdf0e10cSrcweir m_pWizard(_pParent) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir FreeResource(); 89*cdf0e10cSrcweir m_aEditPB.SetClickHdl( LINK( this, SwMailMergePrepareMergePage, EditDocumentHdl_Impl)); 90*cdf0e10cSrcweir Link aMoveLink(LINK( this, SwMailMergePrepareMergePage, MoveHdl_Impl)); 91*cdf0e10cSrcweir m_aFirstPB.SetClickHdl( aMoveLink ); 92*cdf0e10cSrcweir m_aPrevPB.SetClickHdl( aMoveLink ); 93*cdf0e10cSrcweir m_aNextPB.SetClickHdl( aMoveLink ); 94*cdf0e10cSrcweir m_aLastPB.SetClickHdl( aMoveLink ); 95*cdf0e10cSrcweir m_aRecordED.SetActionHdl( aMoveLink ); 96*cdf0e10cSrcweir m_ExcludeCB.SetClickHdl(LINK(this, SwMailMergePrepareMergePage, ExcludeHdl_Impl)); 97*cdf0e10cSrcweir aMoveLink.Call(&m_aRecordED); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir /*-- 02.04.2004 16:42:49--------------------------------------------------- 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 102*cdf0e10cSrcweir SwMailMergePrepareMergePage::~SwMailMergePrepareMergePage() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir /*-- 13.05.2004 15:36:48--------------------------------------------------- 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 108*cdf0e10cSrcweir IMPL_LINK( SwMailMergePrepareMergePage, EditDocumentHdl_Impl, PushButton*, EMPTYARG) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir m_pWizard->SetRestartPage(MM_PREPAREMERGEPAGE); 111*cdf0e10cSrcweir m_pWizard->EndDialog(RET_EDIT_DOC); 112*cdf0e10cSrcweir return 0; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir /*-- 27.05.2004 14:16:37--------------------------------------------------- 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 117*cdf0e10cSrcweir IMPL_LINK( SwMailMergePrepareMergePage, MoveHdl_Impl, void*, pCtrl) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 120*cdf0e10cSrcweir sal_Int32 nPos = rConfigItem.GetResultSetPosition(); 121*cdf0e10cSrcweir if(pCtrl == &m_aFirstPB) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir rConfigItem.MoveResultSet(1); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir else if(pCtrl == &m_aPrevPB) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir rConfigItem.MoveResultSet(nPos - 1); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir else if(pCtrl == &m_aRecordED) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir rConfigItem.MoveResultSet( static_cast< sal_Int32 >(m_aRecordED.GetValue()) ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir else if(pCtrl == &m_aNextPB) 134*cdf0e10cSrcweir rConfigItem.MoveResultSet(nPos + 1); 135*cdf0e10cSrcweir else if(pCtrl == &m_aLastPB) 136*cdf0e10cSrcweir rConfigItem.MoveResultSet(-1); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir nPos = rConfigItem.GetResultSetPosition(); 139*cdf0e10cSrcweir m_aRecordED.SetValue(nPos); 140*cdf0e10cSrcweir bool bIsFirst; 141*cdf0e10cSrcweir bool bIsLast; 142*cdf0e10cSrcweir bool bValid = rConfigItem.IsResultSetFirstLast(bIsFirst, bIsLast); 143*cdf0e10cSrcweir m_aFirstPB.Enable(bValid && !bIsFirst); 144*cdf0e10cSrcweir m_aPrevPB.Enable(bValid && !bIsFirst); 145*cdf0e10cSrcweir m_aNextPB.Enable(bValid && !bIsLast); 146*cdf0e10cSrcweir m_aLastPB.Enable(bValid && !bIsLast); 147*cdf0e10cSrcweir m_ExcludeCB.Check(rConfigItem.IsRecordExcluded( rConfigItem.GetResultSetPosition() )); 148*cdf0e10cSrcweir //now the record has to be merged into the source document 149*cdf0e10cSrcweir const SwDBData& rDBData = rConfigItem.GetCurrentDBData(); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir Sequence< PropertyValue > aArgs(7); 152*cdf0e10cSrcweir Sequence<Any> aSelection(1); 153*cdf0e10cSrcweir aSelection[0] <<= rConfigItem.GetResultSetPosition(); 154*cdf0e10cSrcweir aArgs[0].Name = C2U("Selection"); 155*cdf0e10cSrcweir aArgs[0].Value <<= aSelection; 156*cdf0e10cSrcweir aArgs[1].Name = C2U("DataSourceName"); 157*cdf0e10cSrcweir aArgs[1].Value <<= rDBData.sDataSource; 158*cdf0e10cSrcweir aArgs[2].Name = C2U("Command"); 159*cdf0e10cSrcweir aArgs[2].Value <<= rDBData.sCommand; 160*cdf0e10cSrcweir aArgs[3].Name = C2U("CommandType"); 161*cdf0e10cSrcweir aArgs[3].Value <<= rDBData.nCommandType; 162*cdf0e10cSrcweir aArgs[4].Name = C2U("ActiveConnection"); 163*cdf0e10cSrcweir aArgs[4].Value <<= rConfigItem.GetConnection().getTyped(); 164*cdf0e10cSrcweir aArgs[5].Name = C2U("Filter"); 165*cdf0e10cSrcweir aArgs[5].Value <<= rConfigItem.GetFilter(); 166*cdf0e10cSrcweir aArgs[6].Name = C2U("Cursor"); 167*cdf0e10cSrcweir aArgs[6].Value <<= rConfigItem.GetResultSet(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir ::svx::ODataAccessDescriptor aDescriptor(aArgs); 170*cdf0e10cSrcweir SwWrtShell& rSh = m_pWizard->GetSwView()->GetWrtShell(); 171*cdf0e10cSrcweir SwMergeDescriptor aMergeDesc( DBMGR_MERGE, rSh, aDescriptor ); 172*cdf0e10cSrcweir rSh.GetNewDBMgr()->MergeNew(aMergeDesc); 173*cdf0e10cSrcweir return 0; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir /*-- 27.05.2004 14:46:28--------------------------------------------------- 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 178*cdf0e10cSrcweir IMPL_LINK( SwMailMergePrepareMergePage, ExcludeHdl_Impl, CheckBox*, pBox) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 181*cdf0e10cSrcweir rConfigItem.ExcludeRecord( rConfigItem.GetResultSetPosition(), pBox->IsChecked()); 182*cdf0e10cSrcweir return 0; 183*cdf0e10cSrcweir }; 184*cdf0e10cSrcweir /*-- 18.08.2004 10:36:25--------------------------------------------------- 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 187*cdf0e10cSrcweir void SwMailMergePrepareMergePage::ActivatePage() 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir MoveHdl_Impl(&m_aRecordED); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir /*-- 13.05.2004 15:38:32--------------------------------------------------- 192*cdf0e10cSrcweir merge the data into a new file 193*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 194*cdf0e10cSrcweir sal_Bool SwMailMergePrepareMergePage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 197*cdf0e10cSrcweir if(::svt::WizardTypes::eTravelForward == _eReason && !rConfigItem.IsMergeDone()) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir m_pWizard->CreateTargetDocument(); 200*cdf0e10cSrcweir m_pWizard->SetRestartPage(MM_MERGEPAGE); 201*cdf0e10cSrcweir m_pWizard->EndDialog(RET_TARGET_CREATED); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir return sal_True; 204*cdf0e10cSrcweir } 205