1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #ifdef SW_DLLIMPLEMENTATION 32 #undef SW_DLLIMPLEMENTATION 33 #endif 34 #include <mmpreparemergepage.hxx> 35 #include <mailmergewizard.hxx> 36 #include <mmconfigitem.hxx> 37 #ifndef _DBUI_HRC 38 #include <dbui.hrc> 39 #endif 40 #include <swtypes.hxx> 41 #ifndef _VIEW_HXX 42 #include <view.hxx> 43 #endif 44 #ifndef _DBMGR_HXX 45 #include <dbmgr.hxx> 46 #endif 47 #include <wrtsh.hxx> 48 #include <svx/dataaccessdescriptor.hxx> 49 #include <com/sun/star/sdbc/XConnection.hpp> 50 #include <swabstdlg.hxx> 51 52 53 #include <mmpreparemergepage.hrc> 54 #include <dbui.hrc> 55 56 #include <unomid.h> 57 58 using namespace ::com::sun::star::uno; 59 using namespace ::com::sun::star::beans; 60 using namespace ::com::sun::star::sdbc; 61 using ::rtl::OUString; 62 63 /*-- 02.04.2004 16:42:49--------------------------------------------------- 64 65 -----------------------------------------------------------------------*/ 66 SwMailMergePrepareMergePage::SwMailMergePrepareMergePage( SwMailMergeWizard* _pParent) : 67 svt::OWizardPage( _pParent, SW_RES(DLG_MM_PREPAREMERGE_PAGE)), 68 #ifdef MSC 69 #pragma warning (disable : 4355) 70 #endif 71 m_aHeaderFI(this, SW_RES( FI_HEADER ) ), 72 m_aPreviewFI(this, SW_RES( FI_PREVIEW ) ), 73 m_aRecipientFT(this, SW_RES( FT_RECIPIENT ) ), 74 m_aFirstPB(this, SW_RES( PB_FIRST ) ), 75 m_aPrevPB(this, SW_RES( PB_PREV ) ), 76 m_aRecordED(this, SW_RES( ED_RECORD ) ), 77 m_aNextPB(this, SW_RES( PB_NEXT ) ), 78 m_aLastPB(this, SW_RES( PB_LAST ) ), 79 m_ExcludeCB(this, SW_RES( CB_EXCLUDE ) ), 80 m_aNoteHeaderFL(this, SW_RES( FL_NOTEHEADER ) ), 81 m_aEditFI(this, SW_RES( FI_EDIT ) ), 82 m_aEditPB(this, SW_RES( PB_EDIT ) ), 83 #ifdef MSC 84 #pragma warning (default : 4355) 85 #endif 86 m_pWizard(_pParent) 87 { 88 FreeResource(); 89 m_aEditPB.SetClickHdl( LINK( this, SwMailMergePrepareMergePage, EditDocumentHdl_Impl)); 90 Link aMoveLink(LINK( this, SwMailMergePrepareMergePage, MoveHdl_Impl)); 91 m_aFirstPB.SetClickHdl( aMoveLink ); 92 m_aPrevPB.SetClickHdl( aMoveLink ); 93 m_aNextPB.SetClickHdl( aMoveLink ); 94 m_aLastPB.SetClickHdl( aMoveLink ); 95 m_aRecordED.SetActionHdl( aMoveLink ); 96 m_ExcludeCB.SetClickHdl(LINK(this, SwMailMergePrepareMergePage, ExcludeHdl_Impl)); 97 aMoveLink.Call(&m_aRecordED); 98 } 99 /*-- 02.04.2004 16:42:49--------------------------------------------------- 100 101 -----------------------------------------------------------------------*/ 102 SwMailMergePrepareMergePage::~SwMailMergePrepareMergePage() 103 { 104 } 105 /*-- 13.05.2004 15:36:48--------------------------------------------------- 106 107 -----------------------------------------------------------------------*/ 108 IMPL_LINK( SwMailMergePrepareMergePage, EditDocumentHdl_Impl, PushButton*, EMPTYARG) 109 { 110 m_pWizard->SetRestartPage(MM_PREPAREMERGEPAGE); 111 m_pWizard->EndDialog(RET_EDIT_DOC); 112 return 0; 113 } 114 /*-- 27.05.2004 14:16:37--------------------------------------------------- 115 116 -----------------------------------------------------------------------*/ 117 IMPL_LINK( SwMailMergePrepareMergePage, MoveHdl_Impl, void*, pCtrl) 118 { 119 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 120 sal_Int32 nPos = rConfigItem.GetResultSetPosition(); 121 if(pCtrl == &m_aFirstPB) 122 { 123 rConfigItem.MoveResultSet(1); 124 } 125 else if(pCtrl == &m_aPrevPB) 126 { 127 rConfigItem.MoveResultSet(nPos - 1); 128 } 129 else if(pCtrl == &m_aRecordED) 130 { 131 rConfigItem.MoveResultSet( static_cast< sal_Int32 >(m_aRecordED.GetValue()) ); 132 } 133 else if(pCtrl == &m_aNextPB) 134 rConfigItem.MoveResultSet(nPos + 1); 135 else if(pCtrl == &m_aLastPB) 136 rConfigItem.MoveResultSet(-1); 137 138 nPos = rConfigItem.GetResultSetPosition(); 139 m_aRecordED.SetValue(nPos); 140 bool bIsFirst; 141 bool bIsLast; 142 bool bValid = rConfigItem.IsResultSetFirstLast(bIsFirst, bIsLast); 143 m_aFirstPB.Enable(bValid && !bIsFirst); 144 m_aPrevPB.Enable(bValid && !bIsFirst); 145 m_aNextPB.Enable(bValid && !bIsLast); 146 m_aLastPB.Enable(bValid && !bIsLast); 147 m_ExcludeCB.Check(rConfigItem.IsRecordExcluded( rConfigItem.GetResultSetPosition() )); 148 //now the record has to be merged into the source document 149 const SwDBData& rDBData = rConfigItem.GetCurrentDBData(); 150 151 Sequence< PropertyValue > aArgs(7); 152 Sequence<Any> aSelection(1); 153 aSelection[0] <<= rConfigItem.GetResultSetPosition(); 154 aArgs[0].Name = C2U("Selection"); 155 aArgs[0].Value <<= aSelection; 156 aArgs[1].Name = C2U("DataSourceName"); 157 aArgs[1].Value <<= rDBData.sDataSource; 158 aArgs[2].Name = C2U("Command"); 159 aArgs[2].Value <<= rDBData.sCommand; 160 aArgs[3].Name = C2U("CommandType"); 161 aArgs[3].Value <<= rDBData.nCommandType; 162 aArgs[4].Name = C2U("ActiveConnection"); 163 aArgs[4].Value <<= rConfigItem.GetConnection().getTyped(); 164 aArgs[5].Name = C2U("Filter"); 165 aArgs[5].Value <<= rConfigItem.GetFilter(); 166 aArgs[6].Name = C2U("Cursor"); 167 aArgs[6].Value <<= rConfigItem.GetResultSet(); 168 169 ::svx::ODataAccessDescriptor aDescriptor(aArgs); 170 SwWrtShell& rSh = m_pWizard->GetSwView()->GetWrtShell(); 171 SwMergeDescriptor aMergeDesc( DBMGR_MERGE, rSh, aDescriptor ); 172 rSh.GetNewDBMgr()->MergeNew(aMergeDesc); 173 return 0; 174 } 175 /*-- 27.05.2004 14:46:28--------------------------------------------------- 176 177 -----------------------------------------------------------------------*/ 178 IMPL_LINK( SwMailMergePrepareMergePage, ExcludeHdl_Impl, CheckBox*, pBox) 179 { 180 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 181 rConfigItem.ExcludeRecord( rConfigItem.GetResultSetPosition(), pBox->IsChecked()); 182 return 0; 183 }; 184 /*-- 18.08.2004 10:36:25--------------------------------------------------- 185 186 -----------------------------------------------------------------------*/ 187 void SwMailMergePrepareMergePage::ActivatePage() 188 { 189 MoveHdl_Impl(&m_aRecordED); 190 } 191 /*-- 13.05.2004 15:38:32--------------------------------------------------- 192 merge the data into a new file 193 -----------------------------------------------------------------------*/ 194 sal_Bool SwMailMergePrepareMergePage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 195 { 196 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem(); 197 if(::svt::WizardTypes::eTravelForward == _eReason && !rConfigItem.IsMergeDone()) 198 { 199 m_pWizard->CreateTargetDocument(); 200 m_pWizard->SetRestartPage(MM_MERGEPAGE); 201 m_pWizard->EndDialog(RET_TARGET_CREATED); 202 } 203 return sal_True; 204 } 205