Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <mmpreparemergepage.hxx>
21 : #include <mailmergewizard.hxx>
22 : #include <mmconfigitem.hxx>
23 : #include <dbui.hrc>
24 : #include <swtypes.hxx>
25 : #include <view.hxx>
26 : #include <dbmgr.hxx>
27 : #include <wrtsh.hxx>
28 : #include <svx/dataaccessdescriptor.hxx>
29 : #include <com/sun/star/sdbc/XConnection.hpp>
30 : #include <swabstdlg.hxx>
31 :
32 :
33 : #include <mmpreparemergepage.hrc>
34 :
35 : #include <unomid.h>
36 :
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::beans;
39 : using namespace ::com::sun::star::sdbc;
40 : using ::rtl::OUString;
41 :
42 0 : SwMailMergePrepareMergePage::SwMailMergePrepareMergePage( SwMailMergeWizard* _pParent) :
43 : svt::OWizardPage( _pParent, SW_RES(DLG_MM_PREPAREMERGE_PAGE)),
44 : #ifdef MSC
45 : #pragma warning (disable : 4355)
46 : #endif
47 : m_aHeaderFI(this, SW_RES( FI_HEADER ) ),
48 : m_aPreviewFI(this, SW_RES( FI_PREVIEW ) ),
49 : m_aRecipientFT(this, SW_RES( FT_RECIPIENT ) ),
50 : m_aFirstPB(this, SW_RES( PB_FIRST ) ),
51 : m_aPrevPB(this, SW_RES( PB_PREV ) ),
52 : m_aRecordED(this, SW_RES( ED_RECORD ) ),
53 : m_aNextPB(this, SW_RES( PB_NEXT ) ),
54 : m_aLastPB(this, SW_RES( PB_LAST ) ),
55 : m_ExcludeCB(this, SW_RES( CB_EXCLUDE ) ),
56 : m_aNoteHeaderFL(this, SW_RES( FL_NOTEHEADER ) ),
57 : m_aEditFI(this, SW_RES( FI_EDIT ) ),
58 : m_aEditPB(this, SW_RES( PB_EDIT ) ),
59 : #ifdef MSC
60 : #pragma warning (default : 4355)
61 : #endif
62 0 : m_pWizard(_pParent)
63 : {
64 0 : FreeResource();
65 0 : m_aEditPB.SetClickHdl( LINK( this, SwMailMergePrepareMergePage, EditDocumentHdl_Impl));
66 0 : Link aMoveLink(LINK( this, SwMailMergePrepareMergePage, MoveHdl_Impl));
67 0 : m_aFirstPB.SetClickHdl( aMoveLink );
68 0 : m_aPrevPB.SetClickHdl( aMoveLink );
69 0 : m_aNextPB.SetClickHdl( aMoveLink );
70 0 : m_aLastPB.SetClickHdl( aMoveLink );
71 0 : m_aRecordED.SetActionHdl( aMoveLink );
72 0 : m_ExcludeCB.SetClickHdl(LINK(this, SwMailMergePrepareMergePage, ExcludeHdl_Impl));
73 0 : aMoveLink.Call(&m_aRecordED);
74 0 : }
75 :
76 0 : SwMailMergePrepareMergePage::~SwMailMergePrepareMergePage()
77 : {
78 0 : }
79 :
80 0 : IMPL_LINK_NOARG(SwMailMergePrepareMergePage, EditDocumentHdl_Impl)
81 : {
82 0 : m_pWizard->SetRestartPage(MM_PREPAREMERGEPAGE);
83 0 : m_pWizard->EndDialog(RET_EDIT_DOC);
84 0 : return 0;
85 : }
86 :
87 0 : IMPL_LINK( SwMailMergePrepareMergePage, MoveHdl_Impl, void*, pCtrl)
88 : {
89 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
90 0 : sal_Int32 nPos = rConfigItem.GetResultSetPosition();
91 0 : if(pCtrl == &m_aFirstPB)
92 : {
93 0 : rConfigItem.MoveResultSet(1);
94 : }
95 0 : else if(pCtrl == &m_aPrevPB)
96 : {
97 0 : rConfigItem.MoveResultSet(nPos - 1);
98 : }
99 0 : else if(pCtrl == &m_aRecordED)
100 : {
101 0 : rConfigItem.MoveResultSet( static_cast< sal_Int32 >(m_aRecordED.GetValue()) );
102 : }
103 0 : else if(pCtrl == &m_aNextPB)
104 0 : rConfigItem.MoveResultSet(nPos + 1);
105 0 : else if(pCtrl == &m_aLastPB)
106 0 : rConfigItem.MoveResultSet(-1);
107 :
108 0 : nPos = rConfigItem.GetResultSetPosition();
109 0 : m_aRecordED.SetValue(nPos);
110 : bool bIsFirst;
111 : bool bIsLast;
112 0 : bool bValid = rConfigItem.IsResultSetFirstLast(bIsFirst, bIsLast);
113 0 : m_aFirstPB.Enable(bValid && !bIsFirst);
114 0 : m_aPrevPB.Enable(bValid && !bIsFirst);
115 0 : m_aNextPB.Enable(bValid && !bIsLast);
116 0 : m_aLastPB.Enable(bValid && !bIsLast);
117 0 : m_ExcludeCB.Check(rConfigItem.IsRecordExcluded( rConfigItem.GetResultSetPosition() ));
118 : //now the record has to be merged into the source document
119 0 : const SwDBData& rDBData = rConfigItem.GetCurrentDBData();
120 :
121 0 : Sequence< PropertyValue > aArgs(7);
122 0 : Sequence<Any> aSelection(1);
123 0 : aSelection[0] <<= rConfigItem.GetResultSetPosition();
124 0 : aArgs[0].Name = "Selection";
125 0 : aArgs[0].Value <<= aSelection;
126 0 : aArgs[1].Name = "DataSourceName";
127 0 : aArgs[1].Value <<= rDBData.sDataSource;
128 0 : aArgs[2].Name = "Command";
129 0 : aArgs[2].Value <<= rDBData.sCommand;
130 0 : aArgs[3].Name = "CommandType";
131 0 : aArgs[3].Value <<= rDBData.nCommandType;
132 0 : aArgs[4].Name = "ActiveConnection";
133 0 : aArgs[4].Value <<= rConfigItem.GetConnection().getTyped();
134 0 : aArgs[5].Name = "Filter";
135 0 : aArgs[5].Value <<= rConfigItem.GetFilter();
136 0 : aArgs[6].Name = "Cursor";
137 0 : aArgs[6].Value <<= rConfigItem.GetResultSet();
138 :
139 0 : ::svx::ODataAccessDescriptor aDescriptor(aArgs);
140 0 : SwWrtShell& rSh = m_pWizard->GetSwView()->GetWrtShell();
141 0 : SwMergeDescriptor aMergeDesc( DBMGR_MERGE, rSh, aDescriptor );
142 0 : rSh.GetNewDBMgr()->MergeNew(aMergeDesc);
143 0 : return 0;
144 : }
145 :
146 0 : IMPL_LINK( SwMailMergePrepareMergePage, ExcludeHdl_Impl, CheckBox*, pBox)
147 : {
148 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
149 0 : rConfigItem.ExcludeRecord( rConfigItem.GetResultSetPosition(), pBox->IsChecked());
150 0 : return 0;
151 : };
152 :
153 0 : void SwMailMergePrepareMergePage::ActivatePage()
154 : {
155 0 : MoveHdl_Impl(&m_aRecordED);
156 0 : }
157 :
158 : /*-------------------------------------------------------------------------
159 : merge the data into a new file
160 : -----------------------------------------------------------------------*/
161 0 : sal_Bool SwMailMergePrepareMergePage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
162 : {
163 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
164 0 : if(::svt::WizardTypes::eTravelForward == _eReason && !rConfigItem.IsMergeDone())
165 : {
166 0 : m_pWizard->CreateTargetDocument();
167 0 : m_pWizard->SetRestartPage(MM_MERGEPAGE);
168 0 : m_pWizard->EndDialog(RET_TARGET_CREATED);
169 : }
170 0 : return sal_True;
171 0 : }
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|