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