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