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 : #include <unomid.h>
33 :
34 : using namespace ::com::sun::star::uno;
35 : using namespace ::com::sun::star::beans;
36 : using namespace ::com::sun::star::sdbc;
37 :
38 0 : SwMailMergePrepareMergePage::SwMailMergePrepareMergePage( SwMailMergeWizard* _pParent)
39 : : svt::OWizardPage(_pParent, "MMPreparePage", "modules/swriter/ui/mmpreparepage.ui")
40 0 : , m_pWizard(_pParent)
41 : {
42 0 : get(m_pFirstPB, "first");
43 0 : get(m_pPrevPB, "prev");
44 0 : get(m_pRecordED, "record-nospin");
45 0 : get(m_pNextPB, "next");
46 0 : get(m_pLastPB, "last");
47 0 : get(m_pExcludeCB, "exclude");
48 0 : get(m_pEditPB, "edit");
49 :
50 0 : m_pEditPB->SetClickHdl( LINK( this, SwMailMergePrepareMergePage, EditDocumentHdl_Impl));
51 0 : Link<> aMoveLink(LINK( this, SwMailMergePrepareMergePage, MoveHdl_Impl));
52 0 : m_pFirstPB->SetClickHdl( aMoveLink );
53 0 : m_pPrevPB->SetClickHdl( aMoveLink );
54 0 : m_pNextPB->SetClickHdl( aMoveLink );
55 0 : m_pLastPB->SetClickHdl( aMoveLink );
56 0 : m_pRecordED->SetModifyHdl( aMoveLink );
57 0 : m_pExcludeCB->SetClickHdl(LINK(this, SwMailMergePrepareMergePage, ExcludeHdl_Impl));
58 0 : aMoveLink.Call(m_pRecordED);
59 0 : }
60 :
61 0 : SwMailMergePrepareMergePage::~SwMailMergePrepareMergePage()
62 : {
63 0 : disposeOnce();
64 0 : }
65 :
66 0 : void SwMailMergePrepareMergePage::dispose()
67 : {
68 0 : m_pFirstPB.clear();
69 0 : m_pPrevPB.clear();
70 0 : m_pRecordED.clear();
71 0 : m_pNextPB.clear();
72 0 : m_pLastPB.clear();
73 0 : m_pExcludeCB.clear();
74 0 : m_pEditPB.clear();
75 0 : m_pWizard.clear();
76 0 : svt::OWizardPage::dispose();
77 0 : }
78 :
79 0 : IMPL_LINK_NOARG(SwMailMergePrepareMergePage, EditDocumentHdl_Impl)
80 : {
81 0 : m_pWizard->SetRestartPage(MM_PREPAREMERGEPAGE);
82 0 : m_pWizard->EndDialog(RET_EDIT_DOC);
83 0 : return 0;
84 : }
85 :
86 0 : IMPL_LINK( SwMailMergePrepareMergePage, MoveHdl_Impl, void*, pCtrl)
87 : {
88 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
89 0 : sal_Int32 nPos = rConfigItem.GetResultSetPosition();
90 0 : if (pCtrl == m_pFirstPB)
91 : {
92 0 : rConfigItem.MoveResultSet(1);
93 : }
94 0 : else if (pCtrl == m_pPrevPB)
95 : {
96 0 : rConfigItem.MoveResultSet(nPos - 1);
97 : }
98 0 : else if (pCtrl == m_pRecordED)
99 : {
100 0 : rConfigItem.MoveResultSet( static_cast< sal_Int32 >(m_pRecordED->GetValue()) );
101 : }
102 0 : else if (pCtrl == m_pNextPB)
103 0 : rConfigItem.MoveResultSet(nPos + 1);
104 0 : else if (pCtrl == m_pLastPB)
105 0 : rConfigItem.MoveResultSet(-1);
106 :
107 0 : nPos = rConfigItem.GetResultSetPosition();
108 0 : m_pRecordED->SetValue(nPos);
109 : bool bIsFirst;
110 : bool bIsLast;
111 0 : bool bValid = rConfigItem.IsResultSetFirstLast(bIsFirst, bIsLast);
112 0 : m_pFirstPB->Enable(bValid && !bIsFirst);
113 0 : m_pPrevPB->Enable(bValid && !bIsFirst);
114 0 : m_pNextPB->Enable(bValid && !bIsLast);
115 0 : m_pLastPB->Enable(bValid && !bIsLast);
116 0 : m_pExcludeCB->Check(rConfigItem.IsRecordExcluded( rConfigItem.GetResultSetPosition() ));
117 : //now the record has to be merged into the source document
118 0 : const SwDBData& rDBData = rConfigItem.GetCurrentDBData();
119 :
120 0 : Sequence< PropertyValue > aArgs(7);
121 0 : Sequence<Any> aSelection(1);
122 0 : aSelection[0] <<= rConfigItem.GetResultSetPosition();
123 0 : aArgs[0].Name = "Selection";
124 0 : aArgs[0].Value <<= aSelection;
125 0 : aArgs[1].Name = "DataSourceName";
126 0 : aArgs[1].Value <<= rDBData.sDataSource;
127 0 : aArgs[2].Name = "Command";
128 0 : aArgs[2].Value <<= rDBData.sCommand;
129 0 : aArgs[3].Name = "CommandType";
130 0 : aArgs[3].Value <<= rDBData.nCommandType;
131 0 : aArgs[4].Name = "ActiveConnection";
132 0 : aArgs[4].Value <<= rConfigItem.GetConnection().getTyped();
133 0 : aArgs[5].Name = "Filter";
134 0 : aArgs[5].Value <<= rConfigItem.GetFilter();
135 0 : aArgs[6].Name = "Cursor";
136 0 : aArgs[6].Value <<= rConfigItem.GetResultSet();
137 :
138 0 : svx::ODataAccessDescriptor aDescriptor(aArgs);
139 0 : SwWrtShell& rSh = m_pWizard->GetSwView()->GetWrtShell();
140 0 : SwMergeDescriptor aMergeDesc( DBMGR_MERGE, rSh, aDescriptor );
141 0 : rSh.GetDBManager()->MergeNew(aMergeDesc);
142 0 : return 0;
143 : }
144 :
145 0 : IMPL_LINK( SwMailMergePrepareMergePage, ExcludeHdl_Impl, CheckBox*, pBox)
146 : {
147 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
148 0 : rConfigItem.ExcludeRecord( rConfigItem.GetResultSetPosition(), pBox->IsChecked());
149 0 : return 0;
150 : };
151 :
152 0 : void SwMailMergePrepareMergePage::ActivatePage()
153 : {
154 0 : MoveHdl_Impl(m_pRecordED);
155 0 : }
156 :
157 : // merge the data into a new file
158 0 : bool SwMailMergePrepareMergePage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
159 : {
160 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
161 0 : if(::svt::WizardTypes::eTravelForward == _eReason && !rConfigItem.IsMergeDone())
162 : {
163 0 : m_pWizard->CreateTargetDocument();
164 0 : m_pWizard->SetRestartPage(MM_MERGEPAGE);
165 0 : m_pWizard->EndDialog(RET_TARGET_CREATED);
166 : }
167 0 : return true;
168 0 : }
169 :
170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|