1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
27cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
32cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
33cdf0e10cSrcweir #include <sfx2/new.hxx>
34cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
35cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
36cdf0e10cSrcweir #include <sfx2/docfac.hxx>
37cdf0e10cSrcweir #include <vcl/msgbox.hxx>
38cdf0e10cSrcweir #include <view.hxx>
39cdf0e10cSrcweir #ifndef _DOCSH_HXX
40cdf0e10cSrcweir #include <docsh.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include <mmdocselectpage.hxx>
43cdf0e10cSrcweir #include <mailmergewizard.hxx>
44cdf0e10cSrcweir #include <shellio.hxx>
45cdf0e10cSrcweir #include <swabstdlg.hxx>
46cdf0e10cSrcweir #include <mmconfigitem.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include <dbui.hrc>
49cdf0e10cSrcweir #include <mmdocselectpage.hrc>
50cdf0e10cSrcweir
51cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
52cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
54cdf0e10cSrcweir
55cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
56cdf0e10cSrcweir using namespace ::com::sun::star;
57cdf0e10cSrcweir using namespace ::com::sun::star::uno;
58cdf0e10cSrcweir using namespace svt;
59cdf0e10cSrcweir
60cdf0e10cSrcweir /*-- 02.04.2004 09:40:14---------------------------------------------------
61cdf0e10cSrcweir
62cdf0e10cSrcweir -----------------------------------------------------------------------*/
SwMailMergeDocSelectPage(SwMailMergeWizard * _pParent)63cdf0e10cSrcweir SwMailMergeDocSelectPage::SwMailMergeDocSelectPage( SwMailMergeWizard* _pParent ) :
64cdf0e10cSrcweir svt::OWizardPage(_pParent, SW_RES(DLG_MM_DOCSELECT_PAGE)),
65cdf0e10cSrcweir #ifdef MSC
66cdf0e10cSrcweir #pragma warning (disable : 4355)
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir m_aHeaderFI(this, SW_RES( FI_HEADER ) ),
69cdf0e10cSrcweir m_aHowToFT (this, SW_RES( FT_HOWTO )),
70cdf0e10cSrcweir m_aCurrentDocRB (this, SW_RES( RB_CURRENTDOC )),
71cdf0e10cSrcweir m_aNewDocRB (this, SW_RES( RB_NEWDOC )),
72cdf0e10cSrcweir m_aLoadDocRB (this, SW_RES( RB_LOADDOC )),
73cdf0e10cSrcweir m_aLoadTemplateRB (this, SW_RES( RB_LOADTEMPLATE )),
74cdf0e10cSrcweir m_aRecentDocRB (this, SW_RES( RB_RECENTDOC )),
75cdf0e10cSrcweir m_aBrowseDocPB (this, SW_RES( PB_LOADDOC )),
76cdf0e10cSrcweir m_aBrowseTemplatePB (this, SW_RES( PB_BROWSETEMPLATE )),
77cdf0e10cSrcweir m_aRecentDocLB (this, SW_RES( LB_RECENTDOC )),
78cdf0e10cSrcweir #ifdef MSC
79cdf0e10cSrcweir #pragma warning (default : 4355)
80cdf0e10cSrcweir #endif
81cdf0e10cSrcweir m_pWizard(_pParent)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir FreeResource();
84cdf0e10cSrcweir
85cdf0e10cSrcweir m_aCurrentDocRB.Check();
86cdf0e10cSrcweir DocSelectHdl(&m_aNewDocRB);
87cdf0e10cSrcweir
88cdf0e10cSrcweir Link aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
89cdf0e10cSrcweir m_aCurrentDocRB.SetClickHdl(aDocSelectLink);
90cdf0e10cSrcweir m_aNewDocRB.SetClickHdl(aDocSelectLink);
91cdf0e10cSrcweir m_aLoadDocRB.SetClickHdl(aDocSelectLink);
92cdf0e10cSrcweir m_aLoadTemplateRB.SetClickHdl(aDocSelectLink);
93cdf0e10cSrcweir m_aRecentDocRB.SetClickHdl(aDocSelectLink);
94cdf0e10cSrcweir
95cdf0e10cSrcweir Link aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
96cdf0e10cSrcweir m_aBrowseDocPB.SetClickHdl(aFileSelectHdl);
97cdf0e10cSrcweir m_aBrowseTemplatePB.SetClickHdl(aFileSelectHdl);
98cdf0e10cSrcweir
99cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString >& rDocs =
100cdf0e10cSrcweir m_pWizard->GetConfigItem().GetSavedDocuments();
101cdf0e10cSrcweir for(sal_Int32 nDoc = 0; nDoc < rDocs.getLength(); ++nDoc)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir //insert in reverse order
104cdf0e10cSrcweir m_aRecentDocLB.InsertEntry(rDocs[nDoc], 0);
105cdf0e10cSrcweir }
106cdf0e10cSrcweir m_aRecentDocLB.SelectEntryPos(0);
107cdf0e10cSrcweir if(!rDocs.getLength())
108cdf0e10cSrcweir {
109cdf0e10cSrcweir m_aRecentDocRB.Enable(sal_False);
110cdf0e10cSrcweir }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir /*-- 02.04.2004 09:40:14---------------------------------------------------
114cdf0e10cSrcweir
115cdf0e10cSrcweir -----------------------------------------------------------------------*/
~SwMailMergeDocSelectPage()116cdf0e10cSrcweir SwMailMergeDocSelectPage::~SwMailMergeDocSelectPage()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir /*-- 05.04.2004 14:21:48---------------------------------------------------
121cdf0e10cSrcweir
122cdf0e10cSrcweir -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeDocSelectPage,DocSelectHdl,RadioButton *,pButton)123cdf0e10cSrcweir IMPL_LINK(SwMailMergeDocSelectPage, DocSelectHdl, RadioButton*, pButton)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir m_aRecentDocLB.Enable(&m_aRecentDocRB == pButton);
126cdf0e10cSrcweir
127cdf0e10cSrcweir m_pWizard->UpdateRoadmap();
128cdf0e10cSrcweir m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
129cdf0e10cSrcweir
130cdf0e10cSrcweir return 0;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir /*-- 05.04.2004 14:25:12---------------------------------------------------
133cdf0e10cSrcweir
134cdf0e10cSrcweir -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeDocSelectPage,FileSelectHdl,PushButton *,pButton)135cdf0e10cSrcweir IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, PushButton*, pButton)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir bool bTemplate = &m_aBrowseTemplatePB == pButton;
138cdf0e10cSrcweir
139cdf0e10cSrcweir if(bTemplate)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir m_aLoadTemplateRB.Check();
142cdf0e10cSrcweir SfxNewFileDialog* pNewFileDlg = new SfxNewFileDialog(this, 0);
143cdf0e10cSrcweir //pNewFileDlg->SetTemplateFlags(nFlags);
144cdf0e10cSrcweir sal_uInt16 nRet = pNewFileDlg->Execute();
145cdf0e10cSrcweir if(RET_TEMPLATE_LOAD == nRet)
146cdf0e10cSrcweir bTemplate = false;
147cdf0e10cSrcweir else if(RET_CANCEL != nRet)
148cdf0e10cSrcweir m_sLoadTemplateName = pNewFileDlg->GetTemplateFileName();
149cdf0e10cSrcweir delete pNewFileDlg;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir else
152cdf0e10cSrcweir m_aLoadDocRB.Check();
153cdf0e10cSrcweir
154cdf0e10cSrcweir if(!bTemplate)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
157cdf0e10cSrcweir Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
158cdf0e10cSrcweir
159cdf0e10cSrcweir xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
160cdf0e10cSrcweir
161cdf0e10cSrcweir SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
162cdf0e10cSrcweir SfxFilterMatcher aMatcher( String::CreateFromAscii(rFact.GetShortName()) );
163cdf0e10cSrcweir SfxFilterMatcherIter aIter( &aMatcher );
164cdf0e10cSrcweir Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
165cdf0e10cSrcweir const SfxFilter* pFlt = aIter.First();
166cdf0e10cSrcweir while( pFlt )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir if( pFlt && pFlt->IsAllowedAsTemplate() )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir const String sWild = ((WildCard&)pFlt->GetWildcard()).GetWildCard();
171cdf0e10cSrcweir xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
172cdf0e10cSrcweir
173cdf0e10cSrcweir // #i40125
174cdf0e10cSrcweir if(pFlt->GetFilterFlags() & SFX_FILTER_DEFAULT)
175cdf0e10cSrcweir xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir
179cdf0e10cSrcweir pFlt = aIter.Next();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir if( ERRCODE_NONE == aDlgHelper.Execute() )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir m_sLoadFileName = xFP->getFiles().getConstArray()[0];
185cdf0e10cSrcweir }
186cdf0e10cSrcweir }
187cdf0e10cSrcweir m_pWizard->UpdateRoadmap();
188cdf0e10cSrcweir m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
189cdf0e10cSrcweir
190cdf0e10cSrcweir return 0;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir /*-- 06.04.2004 12:52:24---------------------------------------------------
194cdf0e10cSrcweir
195cdf0e10cSrcweir -----------------------------------------------------------------------*/
commitPage(::svt::WizardTypes::CommitPageReason _eReason)196cdf0e10cSrcweir sal_Bool SwMailMergeDocSelectPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir sal_Bool bReturn = sal_False;
199cdf0e10cSrcweir bool bNext = _eReason == ::svt::WizardTypes::eTravelForward;
200cdf0e10cSrcweir if(bNext || _eReason == ::svt::WizardTypes::eValidate )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir ::rtl::OUString sReloadDocument;
203cdf0e10cSrcweir bReturn = m_aCurrentDocRB.IsChecked() ||
204cdf0e10cSrcweir m_aNewDocRB.IsChecked() ||
205cdf0e10cSrcweir ((sReloadDocument = m_sLoadFileName).getLength() && m_aLoadDocRB.IsChecked() )||
206cdf0e10cSrcweir ((sReloadDocument = m_sLoadTemplateName).getLength() && m_aLoadTemplateRB.IsChecked())||
207cdf0e10cSrcweir (m_aRecentDocRB.IsChecked() && (sReloadDocument = m_aRecentDocLB.GetSelectEntry()).getLength());
208cdf0e10cSrcweir if( _eReason == ::svt::WizardTypes::eValidate )
209cdf0e10cSrcweir m_pWizard->SetDocumentLoad(!m_aCurrentDocRB.IsChecked());
210cdf0e10cSrcweir
211cdf0e10cSrcweir if(bNext && !m_aCurrentDocRB.IsChecked())
212cdf0e10cSrcweir {
213cdf0e10cSrcweir if(sReloadDocument.getLength())
214cdf0e10cSrcweir m_pWizard->SetReloadDocument( sReloadDocument );
215cdf0e10cSrcweir m_pWizard->SetRestartPage(MM_OUTPUTTYPETPAGE);
216cdf0e10cSrcweir m_pWizard->EndDialog(RET_LOAD_DOC);
217cdf0e10cSrcweir }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir return bReturn;
220cdf0e10cSrcweir }
221