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