1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
31*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
36*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
37*cdf0e10cSrcweir #include <sfx2/new.hxx>
38*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
39*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
40*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
41*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
42*cdf0e10cSrcweir #include <view.hxx>
43*cdf0e10cSrcweir #ifndef _DOCSH_HXX
44*cdf0e10cSrcweir #include <docsh.hxx>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include <mmdocselectpage.hxx>
47*cdf0e10cSrcweir #include <mailmergewizard.hxx>
48*cdf0e10cSrcweir #include <shellio.hxx>
49*cdf0e10cSrcweir #include <swabstdlg.hxx>
50*cdf0e10cSrcweir #include <mmconfigitem.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include <dbui.hrc>
53*cdf0e10cSrcweir #include <mmdocselectpage.hrc>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
56*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
60*cdf0e10cSrcweir using namespace ::com::sun::star;
61*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
62*cdf0e10cSrcweir using namespace svt;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir /*-- 02.04.2004 09:40:14---------------------------------------------------
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
67*cdf0e10cSrcweir SwMailMergeDocSelectPage::SwMailMergeDocSelectPage( SwMailMergeWizard* _pParent ) :
68*cdf0e10cSrcweir     svt::OWizardPage(_pParent, SW_RES(DLG_MM_DOCSELECT_PAGE)),
69*cdf0e10cSrcweir #ifdef MSC
70*cdf0e10cSrcweir #pragma warning (disable : 4355)
71*cdf0e10cSrcweir #endif
72*cdf0e10cSrcweir     m_aHeaderFI(this,          SW_RES(  FI_HEADER           ) ),
73*cdf0e10cSrcweir     m_aHowToFT          (this, SW_RES( FT_HOWTO )),
74*cdf0e10cSrcweir     m_aCurrentDocRB     (this, SW_RES( RB_CURRENTDOC )),
75*cdf0e10cSrcweir     m_aNewDocRB         (this, SW_RES( RB_NEWDOC )),
76*cdf0e10cSrcweir     m_aLoadDocRB        (this, SW_RES( RB_LOADDOC )),
77*cdf0e10cSrcweir     m_aLoadTemplateRB   (this, SW_RES( RB_LOADTEMPLATE )),
78*cdf0e10cSrcweir     m_aRecentDocRB      (this, SW_RES( RB_RECENTDOC )),
79*cdf0e10cSrcweir     m_aBrowseDocPB      (this, SW_RES( PB_LOADDOC )),
80*cdf0e10cSrcweir     m_aBrowseTemplatePB (this, SW_RES( PB_BROWSETEMPLATE )),
81*cdf0e10cSrcweir     m_aRecentDocLB      (this, SW_RES( LB_RECENTDOC )),
82*cdf0e10cSrcweir #ifdef MSC
83*cdf0e10cSrcweir #pragma warning (default : 4355)
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir     m_pWizard(_pParent)
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     FreeResource();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     m_aCurrentDocRB.Check();
90*cdf0e10cSrcweir     DocSelectHdl(&m_aNewDocRB);
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     Link aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
93*cdf0e10cSrcweir     m_aCurrentDocRB.SetClickHdl(aDocSelectLink);
94*cdf0e10cSrcweir     m_aNewDocRB.SetClickHdl(aDocSelectLink);
95*cdf0e10cSrcweir     m_aLoadDocRB.SetClickHdl(aDocSelectLink);
96*cdf0e10cSrcweir     m_aLoadTemplateRB.SetClickHdl(aDocSelectLink);
97*cdf0e10cSrcweir     m_aRecentDocRB.SetClickHdl(aDocSelectLink);
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     Link aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
100*cdf0e10cSrcweir     m_aBrowseDocPB.SetClickHdl(aFileSelectHdl);
101*cdf0e10cSrcweir     m_aBrowseTemplatePB.SetClickHdl(aFileSelectHdl);
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     const uno::Sequence< ::rtl::OUString >& rDocs =
104*cdf0e10cSrcweir                             m_pWizard->GetConfigItem().GetSavedDocuments();
105*cdf0e10cSrcweir     for(sal_Int32 nDoc = 0; nDoc < rDocs.getLength(); ++nDoc)
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir         //insert in reverse order
108*cdf0e10cSrcweir         m_aRecentDocLB.InsertEntry(rDocs[nDoc], 0);
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir     m_aRecentDocLB.SelectEntryPos(0);
111*cdf0e10cSrcweir     if(!rDocs.getLength())
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir         m_aRecentDocRB.Enable(sal_False);
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir /*-- 02.04.2004 09:40:14---------------------------------------------------
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
120*cdf0e10cSrcweir SwMailMergeDocSelectPage::~SwMailMergeDocSelectPage()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir /*-- 05.04.2004 14:21:48---------------------------------------------------
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
127*cdf0e10cSrcweir IMPL_LINK(SwMailMergeDocSelectPage, DocSelectHdl, RadioButton*, pButton)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     m_aRecentDocLB.Enable(&m_aRecentDocRB == pButton);
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     m_pWizard->UpdateRoadmap();
132*cdf0e10cSrcweir     m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     return 0;
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir /*-- 05.04.2004 14:25:12---------------------------------------------------
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
139*cdf0e10cSrcweir IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, PushButton*, pButton)
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     bool bTemplate = &m_aBrowseTemplatePB == pButton;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     if(bTemplate)
144*cdf0e10cSrcweir     {
145*cdf0e10cSrcweir         m_aLoadTemplateRB.Check();
146*cdf0e10cSrcweir         SfxNewFileDialog* pNewFileDlg = new SfxNewFileDialog(this, 0);
147*cdf0e10cSrcweir         //pNewFileDlg->SetTemplateFlags(nFlags);
148*cdf0e10cSrcweir         sal_uInt16 nRet = pNewFileDlg->Execute();
149*cdf0e10cSrcweir         if(RET_TEMPLATE_LOAD == nRet)
150*cdf0e10cSrcweir             bTemplate = false;
151*cdf0e10cSrcweir         else if(RET_CANCEL != nRet)
152*cdf0e10cSrcweir             m_sLoadTemplateName = pNewFileDlg->GetTemplateFileName();
153*cdf0e10cSrcweir         delete pNewFileDlg;
154*cdf0e10cSrcweir     }
155*cdf0e10cSrcweir     else
156*cdf0e10cSrcweir         m_aLoadDocRB.Check();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     if(!bTemplate)
159*cdf0e10cSrcweir     {
160*cdf0e10cSrcweir         sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
161*cdf0e10cSrcweir         Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir         xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
166*cdf0e10cSrcweir         SfxFilterMatcher aMatcher( String::CreateFromAscii(rFact.GetShortName()) );
167*cdf0e10cSrcweir         SfxFilterMatcherIter aIter( &aMatcher );
168*cdf0e10cSrcweir         Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
169*cdf0e10cSrcweir         const SfxFilter* pFlt = aIter.First();
170*cdf0e10cSrcweir         while( pFlt )
171*cdf0e10cSrcweir         {
172*cdf0e10cSrcweir             if( pFlt && pFlt->IsAllowedAsTemplate() )
173*cdf0e10cSrcweir             {
174*cdf0e10cSrcweir                 const String sWild = ((WildCard&)pFlt->GetWildcard()).GetWildCard();
175*cdf0e10cSrcweir                 xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 				// #i40125
178*cdf0e10cSrcweir 				if(pFlt->GetFilterFlags() & SFX_FILTER_DEFAULT)
179*cdf0e10cSrcweir 					xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
180*cdf0e10cSrcweir             }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir             pFlt = aIter.Next();
184*cdf0e10cSrcweir         }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         if( ERRCODE_NONE == aDlgHelper.Execute() )
187*cdf0e10cSrcweir         {
188*cdf0e10cSrcweir             m_sLoadFileName = xFP->getFiles().getConstArray()[0];
189*cdf0e10cSrcweir         }
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir     m_pWizard->UpdateRoadmap();
192*cdf0e10cSrcweir     m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     return 0;
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir /*-- 06.04.2004 12:52:24---------------------------------------------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
200*cdf0e10cSrcweir sal_Bool SwMailMergeDocSelectPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     sal_Bool bReturn = sal_False;
203*cdf0e10cSrcweir     bool bNext = _eReason == ::svt::WizardTypes::eTravelForward;
204*cdf0e10cSrcweir     if(bNext || _eReason == ::svt::WizardTypes::eValidate )
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         ::rtl::OUString sReloadDocument;
207*cdf0e10cSrcweir         bReturn = m_aCurrentDocRB.IsChecked() ||
208*cdf0e10cSrcweir                 m_aNewDocRB.IsChecked() ||
209*cdf0e10cSrcweir                 ((sReloadDocument = m_sLoadFileName).getLength() && m_aLoadDocRB.IsChecked() )||
210*cdf0e10cSrcweir                 ((sReloadDocument = m_sLoadTemplateName).getLength() && m_aLoadTemplateRB.IsChecked())||
211*cdf0e10cSrcweir                 (m_aRecentDocRB.IsChecked() && (sReloadDocument = m_aRecentDocLB.GetSelectEntry()).getLength());
212*cdf0e10cSrcweir         if( _eReason == ::svt::WizardTypes::eValidate )
213*cdf0e10cSrcweir             m_pWizard->SetDocumentLoad(!m_aCurrentDocRB.IsChecked());
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         if(bNext && !m_aCurrentDocRB.IsChecked())
216*cdf0e10cSrcweir         {
217*cdf0e10cSrcweir             if(sReloadDocument.getLength())
218*cdf0e10cSrcweir                 m_pWizard->SetReloadDocument( sReloadDocument );
219*cdf0e10cSrcweir             m_pWizard->SetRestartPage(MM_OUTPUTTYPETPAGE);
220*cdf0e10cSrcweir             m_pWizard->EndDialog(RET_LOAD_DOC);
221*cdf0e10cSrcweir         }
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir     return bReturn;
224*cdf0e10cSrcweir }
225