1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 #include <mmpreparemergepage.hxx>
31 #include <mailmergewizard.hxx>
32 #include <mmconfigitem.hxx>
33 #ifndef _DBUI_HRC
34 #include <dbui.hrc>
35 #endif
36 #include <swtypes.hxx>
37 #ifndef _VIEW_HXX
38 #include <view.hxx>
39 #endif
40 #ifndef _DBMGR_HXX
41 #include <dbmgr.hxx>
42 #endif
43 #include <wrtsh.hxx>
44 #include <svx/dataaccessdescriptor.hxx>
45 #include <com/sun/star/sdbc/XConnection.hpp>
46 #include <swabstdlg.hxx>
47 
48 
49 #include <mmpreparemergepage.hrc>
50 #include <dbui.hrc>
51 
52 #include <unomid.h>
53 
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::sdbc;
57 using ::rtl::OUString;
58 
59 /*-- 02.04.2004 16:42:49---------------------------------------------------
60 
61   -----------------------------------------------------------------------*/
SwMailMergePrepareMergePage(SwMailMergeWizard * _pParent)62 SwMailMergePrepareMergePage::SwMailMergePrepareMergePage( SwMailMergeWizard* _pParent) :
63     svt::OWizardPage( _pParent, SW_RES(DLG_MM_PREPAREMERGE_PAGE)),
64 #ifdef MSC
65 #pragma warning (disable : 4355)
66 #endif
67     m_aHeaderFI(this,  SW_RES(     FI_HEADER ) ),
68     m_aPreviewFI(this, SW_RES(     FI_PREVIEW ) ),
69     m_aRecipientFT(this, SW_RES(   FT_RECIPIENT ) ),
70     m_aFirstPB(this, SW_RES(       PB_FIRST   ) ),
71     m_aPrevPB(this, SW_RES(        PB_PREV    ) ),
72     m_aRecordED(this, SW_RES(      ED_RECORD  ) ),
73     m_aNextPB(this, SW_RES(        PB_NEXT    ) ),
74     m_aLastPB(this, SW_RES(        PB_LAST    ) ),
75     m_ExcludeCB(this, SW_RES(      CB_EXCLUDE    ) ),
76     m_aNoteHeaderFL(this, SW_RES(  FL_NOTEHEADER ) ),
77     m_aEditFI(this, SW_RES(        FI_EDIT       ) ),
78     m_aEditPB(this, SW_RES(        PB_EDIT       ) ),
79 #ifdef MSC
80 #pragma warning (default : 4355)
81 #endif
82     m_pWizard(_pParent)
83 {
84     FreeResource();
85     m_aEditPB.SetClickHdl( LINK( this, SwMailMergePrepareMergePage, EditDocumentHdl_Impl));
86     Link aMoveLink(LINK( this, SwMailMergePrepareMergePage, MoveHdl_Impl));
87     m_aFirstPB.SetClickHdl( aMoveLink );
88     m_aPrevPB.SetClickHdl( aMoveLink );
89     m_aNextPB.SetClickHdl( aMoveLink );
90     m_aLastPB.SetClickHdl( aMoveLink );
91     m_aRecordED.SetActionHdl( aMoveLink );
92     m_ExcludeCB.SetClickHdl(LINK(this, SwMailMergePrepareMergePage, ExcludeHdl_Impl));
93     aMoveLink.Call(&m_aRecordED);
94 }
95 /*-- 02.04.2004 16:42:49---------------------------------------------------
96 
97   -----------------------------------------------------------------------*/
~SwMailMergePrepareMergePage()98 SwMailMergePrepareMergePage::~SwMailMergePrepareMergePage()
99 {
100 }
101 /*-- 13.05.2004 15:36:48---------------------------------------------------
102 
103   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergePrepareMergePage,EditDocumentHdl_Impl,PushButton *,EMPTYARG)104 IMPL_LINK( SwMailMergePrepareMergePage, EditDocumentHdl_Impl, PushButton*, EMPTYARG)
105 {
106     m_pWizard->SetRestartPage(MM_PREPAREMERGEPAGE);
107     m_pWizard->EndDialog(RET_EDIT_DOC);
108     return 0;
109 }
110 /*-- 27.05.2004 14:16:37---------------------------------------------------
111 
112   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergePrepareMergePage,MoveHdl_Impl,void *,pCtrl)113 IMPL_LINK( SwMailMergePrepareMergePage, MoveHdl_Impl, void*, pCtrl)
114 {
115     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
116     sal_Int32 nPos = rConfigItem.GetResultSetPosition();
117     if(pCtrl == &m_aFirstPB)
118     {
119         rConfigItem.MoveResultSet(1);
120     }
121     else if(pCtrl == &m_aPrevPB)
122     {
123         rConfigItem.MoveResultSet(nPos - 1);
124     }
125     else if(pCtrl == &m_aRecordED)
126     {
127         rConfigItem.MoveResultSet( static_cast< sal_Int32 >(m_aRecordED.GetValue()) );
128     }
129     else if(pCtrl == &m_aNextPB)
130         rConfigItem.MoveResultSet(nPos + 1);
131     else if(pCtrl == &m_aLastPB)
132         rConfigItem.MoveResultSet(-1);
133 
134     nPos = rConfigItem.GetResultSetPosition();
135     m_aRecordED.SetValue(nPos);
136     bool bIsFirst;
137     bool bIsLast;
138     bool bValid = rConfigItem.IsResultSetFirstLast(bIsFirst, bIsLast);
139     m_aFirstPB.Enable(bValid && !bIsFirst);
140     m_aPrevPB.Enable(bValid && !bIsFirst);
141     m_aNextPB.Enable(bValid && !bIsLast);
142     m_aLastPB.Enable(bValid && !bIsLast);
143     m_ExcludeCB.Check(rConfigItem.IsRecordExcluded( rConfigItem.GetResultSetPosition() ));
144     //now the record has to be merged into the source document
145     const SwDBData& rDBData = rConfigItem.GetCurrentDBData();
146 
147     Sequence< PropertyValue > aArgs(7);
148     Sequence<Any> aSelection(1);
149     aSelection[0] <<= rConfigItem.GetResultSetPosition();
150     aArgs[0].Name = C2U("Selection");
151     aArgs[0].Value <<= aSelection;
152     aArgs[1].Name = C2U("DataSourceName");
153     aArgs[1].Value <<= rDBData.sDataSource;
154     aArgs[2].Name = C2U("Command");
155     aArgs[2].Value <<= rDBData.sCommand;
156     aArgs[3].Name = C2U("CommandType");
157     aArgs[3].Value <<= rDBData.nCommandType;
158     aArgs[4].Name = C2U("ActiveConnection");
159     aArgs[4].Value <<=  rConfigItem.GetConnection().getTyped();
160     aArgs[5].Name = C2U("Filter");
161     aArgs[5].Value <<= rConfigItem.GetFilter();
162     aArgs[6].Name = C2U("Cursor");
163     aArgs[6].Value <<= rConfigItem.GetResultSet();
164 
165     ::svx::ODataAccessDescriptor aDescriptor(aArgs);
166     SwWrtShell& rSh = m_pWizard->GetSwView()->GetWrtShell();
167     SwMergeDescriptor aMergeDesc( DBMGR_MERGE, rSh, aDescriptor );
168     rSh.GetNewDBMgr()->MergeNew(aMergeDesc);
169     return 0;
170 }
171 /*-- 27.05.2004 14:46:28---------------------------------------------------
172 
173   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergePrepareMergePage,ExcludeHdl_Impl,CheckBox *,pBox)174 IMPL_LINK( SwMailMergePrepareMergePage, ExcludeHdl_Impl, CheckBox*, pBox)
175 {
176     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
177     rConfigItem.ExcludeRecord( rConfigItem.GetResultSetPosition(), pBox->IsChecked());
178     return 0;
179 };
180 /*-- 18.08.2004 10:36:25---------------------------------------------------
181 
182   -----------------------------------------------------------------------*/
ActivatePage()183 void  SwMailMergePrepareMergePage::ActivatePage()
184 {
185     MoveHdl_Impl(&m_aRecordED);
186 }
187 /*-- 13.05.2004 15:38:32---------------------------------------------------
188     merge the data into a new file
189   -----------------------------------------------------------------------*/
commitPage(::svt::WizardTypes::CommitPageReason _eReason)190 sal_Bool  SwMailMergePrepareMergePage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
191 {
192     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
193     if(::svt::WizardTypes::eTravelForward == _eReason && !rConfigItem.IsMergeDone())
194     {
195         m_pWizard->CreateTargetDocument();
196         m_pWizard->SetRestartPage(MM_MERGEPAGE);
197         m_pWizard->EndDialog(RET_TARGET_CREATED);
198     }
199     return sal_True;
200 }
201