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